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结果:
热门推荐
5 送心的祝福语简短
9 天仙配简短祝福语
10 客户新房祝福语简短大气
11 男生节搞笑简短祝福语
12 校庆祝福语简短独特
13 对情侣朋友祝福语简短
14 厂庆祝福语大全简短
15 文案生日祝福语高级简短
16 女儿生日祝福语英语简短
17 简短新年红包祝福语大全
18 家庭生日祝福语大全简短