我有一张带时间戳的测量表。每5分钟一个数据。 我创建了一个视图来提取每30分钟的平均值/最小值/最大值。问题是我发现这个查询非常慢(总共13290行+/- 5秒......这很少......
有任何优化的想法吗?
我的代码:
SELECT t_mesures.sonde_id AS sonde_id
,min(t_mesures.timestamp) AS start_period
,max(t_mesures.timestamp) AS end_period
,from_unixtime(
unix_timestamp(min(t_mesures.timestamp))+
floor( (unix_timestamp(max(t_mesures.timestamp))-unix_timestamp(min(t_mesures.timestamp)))/2)
) AS mid_period
,timediff(max(t_mesures.timestamp), min(t_mesures.timestamp)) AS dur_period
,avg(t_mesures.Mesure) AS avg_mesure
,min(t_mesures.Mesure) AS min_mesure
,max(t_mesures.Mesure) AS max_mesure
,count(t_mesures.Mesure) as nb_mesure
FROM t_mesures
GROUP BY t_mesures.sonde_id
,(floor((unix_timestamp(t_mesures.timestamp) / 1800)) * 1800)