澳门新葡亰553311b > 新葡亰 计算机网络 > MySQL分数排名同分并列与不并列查询

MySQL分数排名同分并列与不并列查询
2019-12-03 15:04

澳门新葡亰平台网址大全,MySQL分数排名同分并列与不并列查询,mysql分数同分并列

澳门新葡亰网站所有平台,澳门新葡亰553311b,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;

 

Scores表 | Id | Score | | 1 | 3.50 | | 2 | 3.65 | | 3 | 4.00 | | 4 | 3.85 | | 5 | 4.00 | | 6 | 3.65 | 并列...

 

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

Scores表

上一篇:IIS PUT写权限利用演示 下一篇:没有了