如果要取前3或者前10只需要where a.group_id<=3
where a.group_id<=10

SQL如下:效果相当于手动分组,排序,取前N

select a.* 

from

(

select t1.*,(select count(*)+1 from t_product_info1 where store_name=t1.store_name and sell_num>t1.sell_num) as group_id

from t_product_info1 t1

) a

where a.group_id<=1

Logo

更多推荐