我有一张Sale表
Store | Transaction | ItemID
A | 1000 | A1
A | 1000 | A2
A | 1001 | A3
A | 1001 | A3
A | 1001 | A4
B | 2000 | B1
B | 2000 | B3
B | 2001 | B2
B | 2002 | B4
我想查询以下计算结果:
Store | Total Transactions | Total Item Sales
A | 2 | 5
B | 3 | 4
你能帮忙吗?
答案 0 :(得分:2)
我认为你是SQL的新手。查询是一个简单的聚合:
select store, count(distinct Transaction) as NumTransactions,
count(*) as NumItems
from t
group by store;