MySQL SELECT n records base on GROUP BY
问题 Lets say I have SQL records: Country | Number USA | 300 USA | 450 USA | 500 USA | 100 UK | 300 UK | 400 UK | 1000 And I am doing something like this: SELECT * FROM table GROUP BY Country . What if, I want to choose to display the result with 2 greatest number only in each country? How can I archive this? The result would be: Country | Number USA | 450 USA | 500 UK | 400 UK | 1000 回答1: Sample data create table data (Country varchar(10), Number int); insert into data select 'USA' , 300 union