Why can't I use dense_rank for SQL 'rank scores'?

爱⌒轻易说出口 提交于 2020-01-30 08:07:56

问题


I'm using the dense_rank function in SQL to solve the leetcode 'rank scores' problem(https://leetcode.com/problems/rank-scores/description/):

select Score, dense_rank() over (order by Score) Rank
from Scores
order by Score desc

It always give me the following error:

Line 2: SyntaxError: near '(order by Score) Rank
from Scores
order by Score desc'

I wonder how to make this answer correct? Thanks a lot!

Also, I realized most people use an answer without using the DENSE_RANK function, which is quite confusing since to me DENSE_RANK is probably the most intuitive way to solve the problem. Anyone have any idea? Thanks again!


回答1:


Edited answer

My SQL does not support dense_rank, it does support other window functions though. Check out this answer for help.

Alternatively you could run the code in another SQL server



来源:https://stackoverflow.com/questions/49844276/why-cant-i-use-dense-rank-for-sql-rank-scores

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!