将两条类似的sql合并

编程入门 行业动态 更新时间:2024-10-27 22:26:56

将<a href=https://www.elefans.com/category/jswz/34/1762578.html style=两条类似的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合并

本文发布于:2023-07-01 06:59:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/972347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两条   类似   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!