mysql查询某字段总数量和该字段不同状态时各自的数量
作者:互联网
查询下表中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
标签:count,case,end,某字,when,choice,mysql,answer,数量 来源: https://www.cnblogs.com/H-Dream/p/12491664.html