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