mysql group by count case when

 
更多
select count(extension_num) as callAll,sum(talk_length) as talkLength,
count(case when call_type=1 then 1 else null end) as callin,
count(case when call_type=0 then 1 else null end) as callout,
COUNT(case when call_type=0 and talk_length>0 then 1 else null end) as calloutYes,
COUNT(case when call_type=0 and talk_length=0 then 1 else null end) as calloutNo,
COUNT(case when call_type=1 and talk_length=0 then 1 else null end) as callinNo,
COUNT(case when call_type=1 and talk_length>0 then 1 else null end) as callInYes,
extension_num from t_call_call_record GROUP BY extension_num;

多条件

select count(id) totalCnt,COUNT(case when warehouse_type=0 then null else 1 end) fixedCnt,
COUNT(case WHEN warehouse_type=1 then 1 
WHEN warehouse_type=2 then 1
when warehouse_type=0 and use_status=1 then 1
else null end) usedCnt
 from storage_warehouse where `status`=0 and delete_status=0;
打赏

本文固定链接: https://www.cxy163.net/archives/3241 | 绝缘体

该日志由 绝缘体.. 于 2020年08月02日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: mysql group by count case when | 绝缘体
关键字: ,

mysql group by count case when:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter