美文网首页
【MYSQL 】统计不同状态值的数量

【MYSQL 】统计不同状态值的数量

作者: 深渊凝视 | 来源:发表于2022-06-22 14:32 被阅读0次

方式一

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
FROM case_info

方式二

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 case_info;

相关文章

网友评论

      本文标题:【MYSQL 】统计不同状态值的数量

      本文链接:https://www.haomeiwen.com/subject/hqxmvrtx.html