Here is my SQL query:
select hck.hacker_id, hck.name, cnt
from (
Hacker as hck
inner join (
Select hacker_id, count(challenge_id) as cnt
from Challenges
group by hacker_id
) chl_count on hck.hacker_id = chl_count.hacker_id
) having cnt = max(cnt) or
cnt in (select cnt
from chl_count
group by cnt
having count(hacker_id) = 1)
order by cnt desc, hck.hacker_id asc;
Here Hackers has schema:
Hackers(name, hacker_id)
And Challenges has schema
Challenges(hacker_id, ,challenge_id)
I don't see any missing parenthesis in the query. So, what is wrong? Also, other syntaxes such as commas are correct as well.