从这个黑客问题https://www.hackerrank.com/challenges/challenges/problem?isFullScreen=true
为什么我的查询不会返回完成最大挑战次数的所有黑客的名字?
我的查询给出了每个黑客的所有名字和所有挑战。
This is my query down below
SELECT am.name,am.names_appeared from (
SELECT Hackers.hacker_id,Hackers.name,Count(name) as names_appeared from Hackers
INNER JOIN Challenges on Hackers.hacker_id = Challenges.hacker_id GROUP BY Hackers.hacker_id,Hackers.name
)am
GROUP BY am.name,am.names_appeared
HAVING am.names_appeared = MAX(am.names_appeared)
`
`
1条答案
按热度按时间jgwigjjp1#
在您的内部查询中添加一个排名,并在您的外部查询中仅保留排名=1。