1, sort, add serial number according to total score
Table structure:
Sql:
SET @row = 0;
SELECT b.*, @row: [Email protected]+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
Results:
2, sort, increase the serial number according to the total score, and in the same
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
Results:
MySQL sort and add serial numbers, fractions are the same and parallel