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