只要数据有相同的排名就一样,排名依次排序 SELECT obj.Dept_Name, obj.CountNo, CASE WHEN @rowtotal = obj.CountNo THEN @rownum WHEN @rowtotal := obj.CountNo THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END AS rownum FROM (select * from (select Dept_Name,count(1) CountNo from view_my_pic_sign where 1=1 group by Dept_Name) x order by x.CountNo desc) AS obj, (SELECT @rownum := 0 ,@rowtotal := NULL) r
执行结果