我遇到問題。所以,我的表格:Sql獲取每個級別的最後3行
id level score
1 1 2
2 1 4
3 2 1
4 3 2
5 4 10
.......................
而且我想得到每個級別的最後3行排序desc。我試過這樣:
select * from table order by score desc group by level LIMIT 3
但是不行。你能幫我嗎 ? THX提前對不起我的英語
可能這個鏈接幫助:http://stackoverflow.com/questions/35363047/random-2-records-according-to-position-and-order-by-position –
@Ahhik Chakraborty給你很好的解決方案,這篇文章也是非常有用的:http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/ – mitkosoft