我是SQL的新手。我想基于两个变量创建两个计数,但我不确定如何在SQL上创建此查询。
Count 1统计每个客户的事务数(客户A在01年1月count=1进行了一次交易;客户A在01年1月count=2进行了第二次交易)。
Count2统计每个客户在不同日期的访问顺序(客户A访问在1月1日count=1;客户A访问在1月2日count=2)。
我想在同一张表中创建2列来显示这些计数。
非常感谢
Elisa
发布于 2015-04-27 23:23:45
试试这个:
select
custid,
(select count(*)
from Transactions
where Transactions.custid = c.custid) Count1,
(select count(*)
from Visits
where Visits.custid = c.custid) Count2
from Customer c;https://stackoverflow.com/questions/29898648
复制相似问题