mysql查询某字段总数量和该字段不同状态时各自的数量
程序员文章站
2022-05-09 20:54:08
...
查询下表中2020年choice_answer值为0,1,2,3,4,5分别对应的数据条数以及choice_answer总数据条数:
sql语句:
select count(case when choice_answer = 0 then 1 end) totallyDisagreeNum,
count(case when choice_answer = 1 then 1 end) partialDisagreementNum,
count(case when choice_answer = 3 then 1 end) indeterminateNum,
count(case when choice_answer = 4 then 1 end) partiallyAgreeNum,
count(case when choice_answer = 5 then 1 end) inFullAgreementNum,
count(case when choice_answer = 2 then 1 end) uninvolvedNum,
count(choice_answer) sumNum
from ls_manager_feedback_plan_example
where create_time = 2020
另灵活用法(网上看的,没有测试过):https://blog.csdn.net/KaiSarH/article/details/103275998