[英]What's wrong with this syntax of Mysql 5.7.27-0?
The link to the problem: Challenges问题的链接:挑战
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;
This compiles perfectly in MySQL workbench 8.0 but fails with Hackerrank's MySQL compiler.这在 MySQL 工作台 8.0 中完美编译,但在 Hackerrank 的 MySQL 编译器中失败。 When I use the query
Select version()
, it returns:当我使用查询
Select version()
时,它返回:
5.7.27-0ubuntu0.18.04.1
Also the error message:还有错误信息:
ERROR 1054 (42S22) at line 1: Unknown column 'h.Hacker_id' in 'field list'
What's wrong with the above syntax?上面的语法有什么问题?
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;
you're missing an alias, check [ADD ALIAS]您缺少别名,请检查 [ADD ALIAS]
I think the alias is missing, try this way:我认为缺少别名,请尝试以下方法:
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.