当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL分数排名同分并列与不并列查询

MySQL分数排名同分并列与不并列查询

2018年02月23日  | 移动技术网IT编程  | 我要评论

年会节目小品剧本,早教好不好,口腔蝇蛆病

Scores表

| Id | Score |
| 1  | 3.50  |
| 2  | 3.65  |
| 3  | 4.00  |
| 4  | 3.85  |
| 5  | 4.00  |
| 6  | 3.65  |

并列

| Score | Rank |
| 4.00  | 1    |
| 4.00  | 1    |
| 3.85  | 2    |
| 3.65  | 3    |
| 3.65  | 3    |
| 3.50  | 4    |
select Score,(select count(distinct Score) from Scores as b where b.Score>a.Score)+1 as Rank from Scores a order by Score desc;

不并列

select Score,(@Numb:=@Numb+1)as Rank from Scores a,(select(@Numb:=0))b order by a.Score desc;

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网