Mysql CASE WHEN 用法


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 的位置不同


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM