Home > Database > Mysql Tutorial > Mysql获取成绩排序后的名次_MySQL

Mysql获取成绩排序后的名次_MySQL

WBOY
Release: 2016-05-30 17:11:14
Original
1587 people have browsed it

其实就是输出mysql的排序后的行号
RT:获取单个用户的成绩在所有用户成绩中的排名
可以分两步: 1、查出所有用户和他们的成绩排名

select id,maxScore,(@rowNum:=@rowNum+1) as rowNo
from t_user,
(select (@rowNum :=0) ) b
order by t_user.maxScore desc 
Copy after login

2、查出某个用户在所有用户成绩中的排名
select u.rowNo from (
select id,(@rowNum:=@rowNum+1) as rowNo
from t_user,
(select (@rowNum :=0) ) b
order by t_user.maxScore desc ) u where u.id="2015091810371700001";
Copy after login

OK~ 一切搞定

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template