mysql 排序设置序号取出某条数据所在序号(排名)
2022-02-10 本文已影响0人
Rinaloving
SELECT a.orderNum AS NRankingNum FROM (SELECT (@i:=@i+1) AS orderNum, pkCode,fkUser,fkSchool,sUserName,nScore FROM `TbPhysicalTestReport` , (SELECT @i:=0) AS i WHERE fkSchool='0001' AND sSemester = '上学期' AND DATE_FORMAT(tCreate,'%Y') = '2022' ORDER BY nScore DESC) a WHERE a.fkUser = '0Z6H';