Reputation: 1870
I use the following query to get the average values per hour for one day, but I don't get it to result the latest data instead of the oldest:
SELECT id, serverID, AVG(performance) as performance, AVG(online) as online, HOUR(timestamp)
FROM stats_server
WHERE serverID= :serverID AND DATE_SUB(`timestamp`,INTERVAL 1 HOUR)
GROUP BY HOUR(timestamp)
ORDER BY id ASC
Upvotes: 3
Views: 6088
Reputation: 1332
You have to mention the last 24 hours data:
SELECT id, serverID, AVG(performance) as performance, AVG(online) as online,
HOUR(timestamp) FROM stats_server
WHERE serverID= :serverID AND DATE_SUB(`timestamp`,INTERVAL 1 HOUR) And
timestamp > DATE_SUB(NOW(), INTERVAL 1 DAY)
GROUP BY HOUR(timestamp)
ORDER BY id ASC
Upvotes: 3