1,排序,根据总分 增加序号

  表结构:

mysql 排序并增加序号,分数相同并列

 

sql:

SET @row=0;
SELECT b.*, @row:=@row+1 rownum FROM (
select *,SUM(a.achievement) as achievementAll from cp_cj as a
where 1=1 GROUP BY a.studentNum order by SUM(a.achievement) DESC limit 0,30
) as b

结果:

mysql 排序并增加序号,分数相同并列

 

2,排序,根据总分 增加序号,并且按照总分相同的并列

sql:

select c.* ,ifnull((
select count(*) from
(
select *,SUM(a.achievement) as achievementAll from cp_cj as a
where 1=1 GROUP BY a.studentNum order by SUM(a.achievement) DESC 
) as b
where c.achievementAll < b.achievementAll

),0)+1 as rownum from
(
select *,SUM(a.achievement) as achievementAll from cp_cj as a
where 1=1 GROUP BY a.studentNum order by SUM(a.achievement) DESC limit 0,30
) as c

结果:

mysql 排序并增加序号,分数相同并列

 

相关文章:

  • 2022-12-23
  • 2021-08-28
  • 2022-02-10
  • 2021-09-27
  • 2022-12-23
  • 2022-03-05
  • 2021-11-04
  • 2021-05-01
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2021-07-21
相关资源
相似解决方案