我需要根据他们在sql server中的标记给学生排名。如果学生得到0分,则等级应为0或 - 。但是当我使用dense_rank()函数时,排名的顺序从0而不是从1开始。任何人都可以帮我查询示例。
提前致谢。
答案 0 :(得分:1)
你是说这个吗?
select
(case when marks=0 then 0 else DENSE_RANK() over (order by marks desc) end) RNK,
marks,
student
from(
select 5 as marks, 'a' student union
select 5 as marks, 'b' student union
select 0 as marks, 'c' student union
select 1 as marks, 'd' student union
select 1 as marks, 'e' student union
select 3 as marks, 'f' student
)x
--order by RNK --Add order by clause if 0th rank to come first.
答案 1 :(得分:0)