简体   繁体   English

MYSQL GROUP BY查询结果似乎限制为31

[英]MYSQL GROUP BY Query results seem limited to 31

I have a Raspberry Pi temperature monitoring system setup and all is running fine except I now noticed that my Daily Min, Max and AVG query do not show more then 31 results. 我有一个Raspberry Pi温度监控系统设置,一切运行正常,除了我现在注意到我的每日最小,最大和AVG查询没有显示超过31个结果。 The problem seems to be with the GROUP BY statement and when I limit the amount of days to anything less then 31 I get all the latest data, but anything more then it will only show the 31 oldest days of data. 问题似乎与GROUP BY语句有关,当我将天数限制为小于31的任何数据时,我会获得所有最新数据,但除此之外,它只会显示31个最早的数据日。 I have a chart that is supposed to show every days MIN, MAX and AVG temperature. 我有一个图表,应该显示每天的MIN,MAX和AVG温度。

Please if somebody can help me. 如果有人可以帮助我。

With this it will only show me data from the 26/05/2014 (first day of my logging) till 27/06/2014 and stop there: 有了这个,它只会显示2014年5月26日(我记录的第一天)到2014年6月27日的数据并停在那里:

SELECT DATE_FORMAT(date,'%d') AS date2, 
   MAX(temperature), 
   MAX(temp2), MIN(temperature), 
   MIN(temp2), AVG(temperature), AVG(temp2) 
FROM data
GROUP BY date2
ORDER BY id ASC

With this it will show the last 31 Days of data (from today minus 30 days) - not what I want: 有了它,它将显示最近31天的数据(从今天减去30天) - 不是我想要的:

mysql_select_db("mysensors", $con);
$result = mysql_query("SELECT DATE_FORMAT(date,'%W %e %b %Y') AS date,
                              MAX(temperature), 
                              MAX(temp2), MIN(temperature), MIN(temp2),
                              AVG(temperature), AVG(temp2) 
                FROM data
                WHERE DATE(`date`) > DATE_SUB(NOW(), INTERVAL 30 DAY)
                GROUP BY DAY(date)
                ORDER BY id ASC") or die ("Imposible");

You are grouping the results by day, which is why you are seeing only 31 results. 您按天分组结果,这就是您只看到31个结果的原因。

There are only 31 unique days (01-31). 只有31个独特的日子(01-31)。

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

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