SELECT
DATE(DTM) AS 'Dia',
ROUND(AVG(TMP)-10) AS 'Graus Dia',
(SELECT
ROUND(AVG(TMP),1)
FROM dados_meteo
WHERE HOUR(DTM)>=18 AND HOUR(DTM)<=22 AND DATE(DTM)=Dia/* AND POM = '[VARIABLE]'*/) AS 'Temp. Crepuscular'
FROM dados_meteo
/*WHERE POM = '[VARIABLE]'*/
GROUP BY DATE(DTM)
表的结构是:
POM Varchar
DTM datetime
RNF double
WET double
HMD double
TMP double
DEW double
INF int
explain select ...
的输出是:
1 PRIMARY dados_meteo ALL NULL NULL NULL NULL 18684 Using where; Using temporary; Using filesort
2 DEPENDENT SUBQUERY dados_meteo ALL NULL NULL NULL NULL 18684 Using where
答案 0 :(得分:1)
在日期和时间部分中分割dtm
。
datem date
timem time
SELECT
datem AS 'Dia'
,ROUND(AVG(TMP)-10) AS 'Graus Dia'
,(SELECT ROUND(AVG(TMP),1)
FROM dados_meteo
WHERE timem BETWEEN maketime(18,0,0) AND maketime(22,0,0)
AND datem = Dia) AS 'Temp. Crepuscular'
FROM dados_meteo
GROUP BY datem
确保您使用timem
和datem
答案 1 :(得分:-1)
至少为DTM
创建一个索引。