繁体   English   中英

Mysql 5.7.27-0 的这种语法有什么问题?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM