select sku_id,sku_name,first_cate_id,second_cate_id,cate_id,id_level,group_price,sales,amt,rank from (
select sku_id,sku_name,first_cate_id,second_cate_id,cate_id,id_level,group_price,sales,amt,@rownum:=@rownum+1 ,
if(@sec=_tmp.second_cate_id,@rank:=@rank+1,@rank:=1) as rank,
@sec:=_tmp.second_cate_id
from (
select sku_id,sku_name,first_cate_id,second_cate_id,cate_id,id_level,group_price,sales,amt from pdd_product_3 order by second_cate_id asc ,amt desc
) _tmp ,
(select @rownum :=0 , @sec := null ,@rank:=0) a
) result
WHERE rank <= 10
没有用到rownum 可以不设置