gpt4 book ai didi

mysql - 获取 SQL 错误 "every derived table must have its own alias sql"

转载 作者:行者123 更新时间:2023-11-29 15:14:41 30 4
gpt4 key购买 nike

如何修复此查询 -

SELECT People.Name, Company.Name 
FROM People
JOIN Company ON People.Current_Company_ID = Company.ID
WHERE Current_Company_ID IN
(SELECT Previous_Company_ID FROM People GROUP BY Previous_Company_ID HAVING Count(Previous_Company_ID) = (SELECT MAX(C) FROM (SELECT COUNT(Previous_Company_Id) AS C FROM People
GROUP BY Previous_Company_Id
ORDER BY COUNT(Previous_Company_Id) DESC)));

<强> People Table 有四列

id, name, previous_company_name, current_company_name

<强> Company Table 有两列

id, name  

最佳答案

替换

    (SELECT COUNT(Previous_Company_Id) AS C 
FROM People GROUP BY Previous_Company_Id ORDER BY COUNT(Previous_Company_Id) DESC)

    (SELECT COUNT(Previous_Company_Id) AS C 
FROM People GROUP BY Previous_Company_Id ORDER BY COUNT(Previous_Company_Id) DESC) AA

您缺少别名。

您的新查询是:

SELECT People.Name, Company.Name 
FROM People JOIN Company ON People.Current_Company_ID = Company.ID WHERE Current_Company_ID IN (SELECT Previous_Company_ID
FROM People GROUP BY Previous_Company_ID HAVING Count(Previous_Company_ID) = (SELECT MAX(C) FROM
(
SELECT COUNT(Previous_Company_Id) AS C
FROM People GROUP BY Previous_Company_Id ORDER BY COUNT(Previous_Company_Id)
DESC
)AA
));

关于mysql - 获取 SQL 错误 "every derived table must have its own alias sql",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59807077/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com