sql優化 分字段統計查詢

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';
相關文章
相關標籤/搜索