我下面的表格有mysql的獲取日期之間唯一的記錄與特定的順序
id | item_id | start_date | end_date | disc_percent
1 | 1 | 2016-12-27 | 2016-12-31 | 50
2 | 2 | 2016-12-27 | 2016-12-31 | 50
3 | 3 | 2016-12-27 | 2016-12-31 | 50
4 | 137 | 2016-12-27 | 2016-12-31 | 50
5 | 1 | 2016-12-28 | 2016-12-29 | 10
和我運行此查詢:
SELECT *
from onsale
WHERE (CURDATE() BETWEEN onsale.start_date
AND onsale.end_date)
order by onsale.start_date DESC,
onsale.end_date ASC
我想唯一的每個ITEM_ID的第一個記錄像這樣:
id | item_id | start_date | end_date | disc_percent
5 | 1 | 2016-12-28 | 2016-12-29 | 10
2 | 2 | 2016-12-27 | 2016-12-31 | 50
3 | 3 | 2016-12-27 | 2016-12-31 | 50
4 | 137 | 2016-12-27 | 2016-12-31 | 50
我怎樣才能得到這個結果? 感謝您的幫助
可能的複製[ROW \ _NUMBER()in MySQL](http://stackoverflow.com/questions/1895110/row-number-in-mysql) –
[Get top n re每組分組結果](http://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results) – shmosel
只讀通過推薦的答案,我不要解開它們 –