sql优化 分字段统计查询
Posted 奥雷连诺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘;
以上是关于sql优化 分字段统计查询的主要内容,如果未能解决你的问题,请参考以下文章