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;

posted @ 2018-07-02 16:16  itvita  阅读(1930)  评论(1编辑  收藏  举报