需要将表A\B\C 的12月11日消耗汇总起来这种sql语句如何写?
select sum(消耗) as 消耗,日期
from (select * from 表A
union all select * from 表B
union all select * from 表C) as t
where 日期='2020/12/11'
group by 日期
三段union all,然后外面再包一层,,进行求和,用日期分组。
select aaa.日期,sum(aaa.消耗) from (
select a.日期,a.消耗 from a
union all
select b.日期,b.消耗 from b
select c.日期,c.消耗 from c
) aaa where 1=1 and aaa.日期='2020/12/11' group by aaa.日期
union all 写太麻烦,通过日期进行关联关联,进行sum,group by 日期即可