实体类
@Data
public class User {
/**
* 排名
*/
private Integer rowNum;
/**
* 用户姓名
*/
private String username;
/**
* 成绩
*/
private Double socre;
}
SQL
select (@r :=@r + 1) as rowNum,username,score
from db_score s,(select @r := 0) r
order by score desc
@r是MySQL中定义一个变量
@r := @r+1
将r+1的值赋值给变量r
(select @r := 0) r
声明变量从0开始