我使用以下查询来获取一天中每小时的平均值,但我不会得到最新数据而不是最旧数据:
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
答案 0 :(得分:2)
您必须提及过去24小时的数据:
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