mysql 8.0.21版本
select e.ename,e.sal,t.* from(select deptno,avg(sal) as salavg from emp group by deptno) as t join emp e on t.deptno=e.deptno and e.sal>t.salavg;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from(select deptno,avg(sal) as salavg from emp group by deptno) as t join emp ' at line 1
但是将子查询的内容放到join后可以正确输出,例如:
select t.*,e.ename,e.sal from emp e join (select deptno,avg(sal) as salavg from emp group by deptno) t on e.deptno=t.deptno and e.sal>t.salavg;
结果为:
| deptno | salavg | ename | sal |
| 30 | 1566.666667 | ALLEN | 1600.00 |
| 20 | 2175.000000 | JONES | 2975.00 |
| 30 | 1566.666667 | BLAKE | 2850.00 |
| 20 | 2175.000000 | SCOTT | 3000.00 |
| 10 | 2916.666667 | KING | 5000.00 |
| 20 | 2175.000000 | FORD | 3000.00 |
请问,究竟什么原因导致from后select子查询出错?
这个是中文括号吧?后边报错就是这附近错误