参考答案:
select Score, (select count(distinct Score) from Scores where Score>=s.Score) as Rank from Scores s
order by Score desc;
答案分析:
(select count(distinct Score) from Scores where Score>=s.Score) as Rank from Scores s
1.统计Scores比s.Scores大或相等的数有多少个,如,Scores:4.00,比它大或者相等的数只有一个,(若去掉distinct,则有两个比4.00大或者相等的数)
2.按Scores倒序排序
知识点补充:
count(distinct 列名)---只包括列名指定列,返回指定列的不同值的记录数,在统计结果的时候,在统计结果的时候,会忽略列值为NULL的记录(不包括空字符串和0),即列值为NULL的记录不统计在内。