第一种 1,2,3,4排序
SELECT a.*, (@i:=@i+1) AS rownum FROM(
SELECT SUM(info.rate*IFNULL(SCORE.score,0)) AS sum_score,score.org_code FROM human_score_info score
LEFT JOIN human_indicator_info info ON score.item_id=info.id
WHERE info.parent_code=#{itemCode} AND info.item_code !=#{itemCode} GROUP BY score.org_code) a ,(SELECT @i:=0) t1 ORDER BY a.sum_score DESC
第二种 1 1 3 4排名方式
select t.score,(select count(s.score)+1 from score s where s.score>t.score) rank from score t order by t.score desc;
第三种 1 1 2 3 排序方式
select t.score,(select count(s.score)+1 from (select s.score,count(s.score) from score s group by score order by score desc) s where s.score>t.score) rank from score t order by t.score desc;
sql排序
于 2021-11-01 18:23:25 首次发布