可以說我有如下表:獲取最新的N記錄爲每組
id coulmn_id value date
1 10 'a' 2016-04-01
1 11 'b' 2015-10-02
1 12 'a' 2016-07-03
1 13 'a' 2015-11-11
2 11 'c' 2016-01-10
2 23 'd' 2016-01-11
3 11 'c' 2016-01-09
3 111 'd' 2016-01-11
3 222 'c' 2016-01-10
3 333 'd' 2016-01-11
n = 3時,我想獲得最新的n條記錄< = 3每個ID。因此,我將有以下的輸出:
id column_id value date
1 10 'a' 2016-04-01
1 12 'a' 2016-07-03
1 13 'a' 2015-11-11
2 11 'c' 2016-01-10
2 23 'd' 2016-01-11
3 111 'd' 2016-01-11
3 222 'c' 2016-01-10
3 333 'd' 2016-01-11
http://stackoverflow.com/questions/12113699/爲每組分組結果得到最多n個記錄結果 – bill
你的主鍵是什麼? – Strawberry
以上問題的解決方案適用於有限數量的'group_name',日期字段可能很大。 – futurenext110