两条类似的sql合并"/>
将两条类似的sql合并
将 coal_code 相同的 合并成 一条数据
select T.coal_code,SUM(T.untreated_figure_num) AS num_a,SUM(T.figure_num) as num_b,T.dataTime from
(
select '0' as untreated_figure_num,COUNT(id) as figure_num,
coal_id as coal_code,
creat_time as dataTime
from hydrology_log
where creat_time between '2022-08-01 00:00:00' and '2022-08-30 23:59:59'
group by coal_idUNION ALLselect COUNT(id) as untreated_figure_num,'0' as figure_num,
coal_id as coal_code,
creat_time as dataTime
from hydrology_log
where creat_time between '2022-08-01 00:00:00' and '2022-08-30 23:59:59'
and deal_with = 1
group by coal_id
) as T
GROUP BY coal_code
最终效果
更多推荐
将两条类似的sql合并
发布评论