select sp.*,
case when @prevRank=product_count then @curRank
when @prevRank := product_count then @curRank := @curRank + 1
when product_count<=0 then @curRank := @curRank + 1
end as cntRank
from staff_product sp,
(select @curRank := 0, @prevRank := NULL) r
order by sp.product_count desc
2.MySQL版本>=8.0
select *,
dense_rank() over (
order by product_count desc
) cntRank
from staff_product