常用sql 小蕊

按条件统计四个季度的测单数量 #
select sum(case when begin>='20201226' and end<='20210325' then 1 else 0 end) as '一季度', sum(case when begin>='20210326' and end<='20210625' then 1 else 0 end) as '二季度', sum(case when begin>='20210626' and end<='20210925' then 1 else 0 end) as '三季度', sum(case when begin>='20210926' and end<='20211225' then 1 else 0 end) as '四季度' from zt_testtask where `owner`in('liqingyun','wangkl','haonan','zhanghongyun','yuping','liuth','zhaobo','zhourui','luoqing','zhaojiaqi')

  

原文地址:https://www.cnblogs.com/ruijie/p/15698829.html