英文:
Can't do the QUERY PostgreSQL. If two athletes received the same number of points, give both the same place
问题
我是新手,不懂如何在PostgreSQL中完成老师给我的任务。我有4列,我需要给Emily和Vanessa分配相同的位置,但我不知道如何做到。
我尝试使用带有IF语句的函数来完成,还尝试通过积分来计算,但都没有得到任何结果。
表格链接:[1]
英文:
[TABLE][1]I'm new at this and can't do the task for my teacher in PostgreSQL. I have 4 columns, I have to give Emily and Vanessa the same place, but I don't understend how to do it
I tried to do it by using function with IF statements, tried to count by Points,but it didn't give any results.
TABLE:
[1]: https://i.stack.imgur.com/1VlMx.png
答案1
得分: 0
The dense_rank
function should do the heavy lifting for you:
SELECT athlete, points, DENSE_RANK() OVER (ORDER BY points DESC) AS place
FROM mytable
英文:
The dense_rank
function should do the heavy lifting for you:
SELECT athlete, points, DENSE_RANK() OVER (ORDER BY points DESC) AS place
FROM mytable
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论