SELECT DATE(FROM_UNIXTIME(time)) AS daygroup,
MAX(value) AS max_value,
MIN(value) AS min_value
FROM tbl
WHERE time >= UNIX_TIMESTAMP(CURDATE() - INTERVAL 7 DAY)
GROUP BY daygroup
これにより、value
の最小値と最大値が取得されます 過去7日間の毎日。
編集: 行全体のデータを取得するための更新されたソリューション:
SELECT a.*
FROM tbl a
INNER JOIN
(
SELECT DATE(FROM_UNIXTIME(time)) AS daygroup,
MAX(value) AS max_value
FROM tbl
WHERE time >= UNIX_TIMESTAMP(CURDATE() - INTERVAL 7 DAY)
GROUP BY daygroup
) b ON DATE(FROM_UNIXTIME(a.time)) = b.daygroup AND a.value = b.max_value