简体   繁体   English

一段时间内每天mysql的平均温度

[英]mysql average temperature of every day in a period

I have a table with date and max temperature. 我有一张桌子,上面有日期和最高温度。

I'm trying to find the average max temperature of each day of the year given a period of years. 我试图找到给定年份的一年中每一天的平均最高温度。 Ex. 防爆。 The average of tmax for 01-01 in the period of 1980 and 2013. 1980年至2013年期间01-01的tmax平均值。

With the following query I found Tmax ordered as I want, but I can't find a way to group by each day. 通过以下查询,我发现Tmax已按需要排序,但找不到每天分组的方法。

$resultat = mysql_query ("SELECT data, Tmax FROM $estacio WHERE data between '1980-01-01' and '2013-12-31' group by day(data),year(data);");

    while($row = mysql_fetch_array($resultat)) { 
      echo '<tr>';
      echo '<td>',$row[0],'</td><td>',$row[1],'</td>';
      echo '</tr>';
    }

This should give you the average max temperatures per day over multiple years. 这应该为您提供多年中每天的平均最高温度。 Each row shows the day and month and the average temperature in the given period for that day. 每行显示日期和月份以及该日期给定时间段内的平均温度。

SELECT
  DAY(data),
  MONTH(data),
  AVG(Tmax)
FROM $estacio 
WHERE data BETWEEN '1980-01-01' AND '2013-12-31'
GROUP BY DAY(data), MONTH(data);

For finding the average surely you would need to use the function AVG() . 为了确定平均值,您需要使用AVG()函数。

Use it like 像这样使用

SELECT
DAY(data)
MONTH(data),
  AVG(Tmax)
FROM $estacio 
WHERE data BETWEEN '1980-01-01' AND '2013-12-31'
GROUP BY DAY(data), MONTH(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM