简体   繁体   中英

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. 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. I have a chart that is supposed to show every days MIN, MAX and AVG temperature.

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:

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:

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.

There are only 31 unique days (01-31).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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