码迷,mamicode.com
首页 > 数据库 > 详细

sql优化 分字段统计查询

时间:2019-11-12 20:08:07      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:dex   where   origin   from   字段   case   sum   cas   char   

select count(1) from pd_xxx_origin_xxx_data where create_time like ‘2019-02-23%‘ and source=‘20036‘
 
SELECT 
sum(case when create_time like ‘2019-02-23%‘ then 1 else 0 end) as inst_count,
sum(case when active_time like ‘2019-02-23%‘ then 1 else 0 end) as active_count
 FROM `pd_xxx_origin_xxx_data` where  charindex(‘20036‘,source );
 
SELECT 
sum(case when create_time like ‘2019-02-23%‘ then 1 else 0 end) as inst_count,
sum(case when active_time like ‘2019-02-23%‘ then 1 else 0 end) as active_count
 FROM `pd_xxx_origin_xxx_data ` where  source like ‘20036%‘;
 
SELECT 
sum(case when create_time like ‘2019-02-23%‘ then 1 else 0 end) as inst_count,
sum(case when active_time like ‘2019-02-23%‘ then 1 else 0 end) as active_count
 FROM `pd_xxx_origin_xxx_data` where  source=‘20052‘;
 

sql优化 分字段统计查询

标签:dex   where   origin   from   字段   case   sum   cas   char   

原文地址:https://www.cnblogs.com/yuzhould/p/11844613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!