mysql查询某字段总数量和该字段不同状态时各自的数量

查询下表中2020年choice_answer值为0,1,2,3,4,5分别对应的数据条数以及choice_answer总数据条数:

mysql查询某字段总数量和该字段不同状态时各自的数量

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

 

上一篇:LeetCode LCP 01. 猜数字 多种语言解法 C/C++/Python/Java


下一篇:LeetCode131分割回文串(回溯算法)