http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
Selecting the one maximum row from each group
mysql - Get top n records for each group of grouped results
SQL: selecting top N records per group
There's a better way: select the variety from each type where the variety is no more than the second-cheapest of that type.
select type, variety, price
from fruits
where (
select count(*) from fruits as f
where f.type = fruits.type and f.price <= fruits.price <--- 这里要注意条件修改!
) <= 2; <-- 这里就是 Top N设定