2
我有,我認爲通常情況下的變化獲取記錄與日期時間分組的最高值每小時
Get records with highest/smallest <whatever> per group
描述這與數據表
id | value1 | value2 | curdate | curtime
1 | 234 | 500 | 2014-10-27 | 12:00:00
2 | 200 | 400 | 2014-10-27 | 12:05:00
3 | 300 | 600 | 2014-10-27 | 12:10:00
4 | 400 | 800 | 2014-10-27 | 12:15:00
5 | 150 | 700 | 2014-10-27 | 12:20:00
...
10 | 134 | 530 | 2014-10-27 | 13:00:00
12 | 220 | 420 | 2014-10-27 | 13:05:00
13 | 330 | 630 | 2014-10-27 | 13:10:00
14 | 440 | 840 | 2014-10-27 | 13:15:00
15 | 120 | 750 | 2014-10-27 | 13:20:00
我想報告的最大值2和相應的值1:
value1 | value2 | curdate | curtime
400 | 800 | 2014-10-27 | 12:00:00
440 | 840 | 2014-10-27 | 13:00:00
我試圖應用上面答案中指定的「標準」解決方案,但沒有成功。使用MySQL。
SELECT t1.*
FROM Table AS t1
LEFT OUTER JOIN `Table` AS t2
ON t1.GroupId = t2.GroupId AND t1.OrderField < t2.OrderField
WHERE t2.GroupId IS NULL
我想是這樣的:
SELECT t1.*
FROM Table AS t1
LEFT OUTER JOIN Table AS t2
ON SUBSTR(CONCAT(t1.curdate, ' ', t1.curtime), 1, 13) = SUBSTR(CONCAT(t2.curdate, ' ', t2.curtime), 1, 13) AND t1.value2 < t2.value2
WHERE ???? IS NULL <--- not sure what to put here
請幫助。謝謝。
輝煌的感謝!不知道我爲什麼困惑。 需要更改%H中的%h。 – murenaj77 2014-10-27 16:38:36