...不同时间段的各自数据各自总和,需要在一个sql里面写出
发布网友
发布时间:2024-10-21 21:54
我来回答
共1个回答
热心网友
时间:2024-11-18 00:26
select
sum(case when e2.record_time between '2015-07-31 00:00:00' and '2015-08-31 00:00:00' then e1.increment_value else 0 end) e1
sum(case when e1.record_time between '2014-07-31 00:00:00' and '2014-08-31 00:00:00' then e1.increment_value else 0 end) e2
from
electric_meter_increment e2,electric_meter_increment e1
where
e2.record_time between '2015-07-31 00:00:00' and '2015-08-31 00:00:00'
and e1.record_time between '2014-07-31 00:00:00' and '2014-08-31 00:00:00'