SQL 条件聚合
示例
付款表
select customer,
sum(case when payment_type = 'credit' then amount else 0 end) as credit,
sum(case when payment_type = 'debit' then amount else 0 end) as debit
from payments
group by customer结果:
select customer,
sum(case when payment_type = 'credit' then 1 else 0 end) as credit_transaction_count,
sum(case when payment_type = 'debit' then 1 else 0 end) as debit_transaction_count
from payments
group by customer结果:
热门推荐
10 运动社团祝福语简短英文
11 写夏至的祝福语简短
12 如何问候生日祝福语简短
13 毕业祝福语给同学 简短
14 宝宝祝福语诗意简短 古文
15 当选团员祝福语简短精辟
16 喜欢的人送礼祝福语简短
17 简短祝福语蛋糕简笔画
18 毕业祝福语简短英语小学