select
sum(case when t.status in (1,3,4,5) then t.total_amount else 0 end) invlid_total_amount,
sum(case when t.status in (2,6) then t.total_amount else 0 end) vlid_total_amount,
sum(case when t.status in (1,3,4,5) then 1 else 0 end) invlid_tickets,
sum(case when t.status in (2,6) then 1 else 0 end) vlid_tickets
from te_ticket t;
结果如下:
invlid_total_amount vlid_total_amount invlid_tickets vlid_tickets
321288 26420 717
105
本文介绍了一个具体的SQL查询案例,展示了如何使用CASE WHEN语句来根据不同条件汇总数据,包括总金额和票数的有效与无效分类。
4521

被折叠的 条评论
为什么被折叠?



