gpt4 book ai didi

mysql - 如何解决此 SQL 错误 : Every derived table must have its own alias?

转载 作者:行者123 更新时间:2023-12-01 00:41:05 30 4
gpt4 key购买 nike

这个 SQL 有什么问题:

SELECT dept_name, avg_salary
FROM (SELECT dept_name, AVG(salary) AS avg_salary
FROM instructor GROUP BY dept_name)
WHERE avg_salary > 42000;

我收到这个错误:

ERROR 1248 (42000): Every derived table must have its own alias

有人帮助我,谢谢。

最佳答案

通过添加如下别名

SELECT dept_name, avg_salary
FROM (SELECT dept_name, AVG(salary) AS avg_salary
FROM instructor GROUP BY dept_name) xxx <-- Here
WHERE avg_salary > 42000;

尽管您可以像下面这样修改您的查询

SELECT dept_name, AVG(salary) AS avg_salary 
FROM instructor
GROUP BY dept_name
HAVING AVG(salary) > 42000;

关于mysql - 如何解决此 SQL 错误 : Every derived table must have its own alias?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32379985/

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