sql优化 分字段统计查询
时间:2021-07-01 10:21:17
帮助过:4人阅读
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