1
我需要回溯今天和上次trhee天的數據並計算mysql中的平均值。回溯今天和最後trhee天的數據,並在mysql中計算平均值
我的查詢是
select aqi_id,
r_aqi_id,
avg(aqi_value),
added_date
from
sfr_aqi
order by
ra.added_date desc
limit 0,3
請建議我更好的辦法。
我需要回溯今天和上次trhee天的數據並計算mysql中的平均值。回溯今天和最後trhee天的數據,並在mysql中計算平均值
我的查詢是
select aqi_id,
r_aqi_id,
avg(aqi_value),
added_date
from
sfr_aqi
order by
ra.added_date desc
limit 0,3
請建議我更好的辦法。
試試這個NOW() - INTERVAL 3 DAY
的最後三天
select aqi_id,
r_aqi_id,
avg(aqi_value),
added_date
from
sfr_aqi
where ra.added_date >= NOW() - INTERVAL 3 DAY
group by aqi_id /* you can also use group by ra.added_date */
order by
ra.added_date desc
limit 0,3
有每個日期只有一個條目此表? – Anton
@Anton否每個日期都有多個條目。 –