Can't do the QUERY PostgreSQL. If two athletes received the same number of points, give both the same place

huangapple go评论52阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 00:54:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定