mysql 统计一个列不同值的数量 /统计某表不同状态值的数量


SELECT
count(status = 0 OR NULL) AS a,
count(status = 1 OR NULL) AS b,
count(status = 2 OR NULL) AS c,
count(status = 3 OR NULL) AS d,
count(status = 4 OR NULL) AS e
FROM table;

 

 

 

SELECT
sum(case when status=1 then 1 else 0 end) AS a,
sum(case when status=2 then 1 else 0 end) AS b,
sum(case when status=3 then 1 else 0 end) AS c,
sum(case when status=4 then 1 else 0 end) AS d
FROM table;


免责声明!

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



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