Mysql CASE WHEN 用法

时间:2017-11-02 16:42:21   收藏:0   阅读:422

select
sum(1) as col_0_0_, sum(case vciinfo.useable when -1 then 1 else 0 end) as col_1_0_,
sum(case when vciinfo.activatetime is null then 0 else 1 end) as col_2_0_
from vci_info vciinfo

这是一个用case when 实现统计表中不同状态数据数量的sql语句

这里要注意的是 判断字段是否为空用 case when vciinfo.activatetime is null   

判断值 case vciinfo.useable when -1

 

when 的位置不同

原文:http://www.cnblogs.com/huhuixin/p/7772874.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!