这段代码给了我一个很好的结果。但是我想从另一个表中添加一些字段,我不确定在哪里放置额外的 WHERE 代码......
select day, sum(diff) as total_diff
from (
select sub_meterID, date(`date`) as day, max(value) - min(value) as diff
from `sub_meter_data`
where date(`date`) > '2012-10-01'
and sub_meterID in ('58984','58985','58986','58987')
group by sub_meterID, date(`date`)
) a
group by day
我需要匹配的其他字段是:
othertable.meterID = sub_meter_data.sub_meterID
moretable.meterID = othertableID