[英]What's wrong with this syntax of Mysql 5.7.27-0?
問題的鏈接:挑戰
Select h.hacker_id, h.name, COUNT(DISTINCT c.Challenge_id) as Cnt from Hackers h
INNER JOIN Challenges c ON h.Hacker_id = c.Hacker_id Having
Cnt = (Select COUNT(DISTINCT Challenge_id) as c_cmp from Challenges
group by Hacker_id order by c_cmp desc LIMIT 1)
OR
Cnt IN (Select final_cnt from (Select h.Hacker_id, h.Name, COUNT(DISTINCT c.Challenge_id) as final_cnt from Hackers
JOIN Challenges c ON h.Hacker_id = c.Hacker_id) as T group by final_cnt having COUNT(final_cnt) = 1)
order by Cnt desc, h.Hacker_id;
這在 MySQL 工作台 8.0 中完美編譯,但在 Hackerrank 的 MySQL 編譯器中失敗。 當我使用查詢Select version()
時,它返回:
5.7.27-0ubuntu0.18.04.1
還有錯誤信息:
ERROR 1054 (42S22) at line 1: Unknown column 'h.Hacker_id' in 'field list'
上面的語法有什么問題?
Select h.hacker_id, h.name, COUNT(DISTINCT c.Challenge_id) as Cnt from Hackers h
INNER JOIN Challenges c ON h.Hacker_id = c.Hacker_id Having
Cnt = (Select COUNT(DISTINCT Challenge_id) as c_cmp from Challenges
group by Hacker_id order by c_cmp desc LIMIT 1)
OR
Cnt IN (Select final_cnt from (Select h.Hacker_id, h.Name, COUNT(DISTINCT c.Challenge_id) as final_cnt from Hackers [ADD ALIAS]
JOIN Challenges c ON h.Hacker_id = c.Hacker_id) as T group by final_cnt having COUNT(final_cnt) = 1)
order by Cnt desc, h.Hacker_id;
您缺少別名,請檢查 [ADD ALIAS]
我認為缺少別名,請嘗試以下方法:
Select h.hacker_id, h.name, COUNT(DISTINCT c.Challenge_id) as Cnt from Hackers h
INNER JOIN Challenges c ON h.Hacker_id = c.Hacker_id Having
Cnt = (Select COUNT(DISTINCT Challenge_id) as c_cmp from Challenges
group by Hacker_id order by c_cmp desc LIMIT 1)
OR
Cnt IN (Select final_cnt from (Select h.Hacker_id, h.Name, COUNT(DISTINCT c.Challenge_id) as final_cnt from **Hackers h**
JOIN Challenges c ON h.Hacker_id = c.Hacker_id) as T group by final_cnt having COUNT(final_cnt) = 1)
order by Cnt desc, h.Hacker_id;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.