方式一:
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