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;

 
分类: sql
posted @ 2020-07-02 16:15  方大帝的博客  阅读(5049)  评论(0编辑  收藏  举报