select a.device_nam,(a.value-isnull(b.value,0)) as value from ( select distinct device_name,kwh as value,SUBSTR(cdate,6,2) 月份 from view_space365_electric where YEAR(cdate) = YEAR(now()) group by device_name,SUBSTR(cdate,6,2) ) a left join ( select distinct device_name,kwh as value,SUBSTR(cdate,6,2) 月份 from view_space365_electric where YEAR(cdate) = YEAR(now()) group by device_name,SUBSTR(cdate,6,2) ) b on a.device_name = b.device_name and a.月份 = b.月份+1 --where a.月份 ='10' |