`
zhenping
  • 浏览: 79441 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

Mysql Case 使用

 
阅读更多
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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics