Mysql报错:Every derived table must have its own alias
造成原因:
在做多表查询,或者对产生的新表进行查询时会出现这个错误
报错解释:
Every derived table must have its own alias
每个派生表都必须有自己的别名
解决方法:
对不同的表或者新表起个别名既可
例如:Leecode 185. 部门工资前三高的所有员工
-- 解析:利用滑动窗口根据所属部门进行分组,按照工资进行降序排列,得到一个表,然后对新表进行选择性查询即可得到工资前三高的员工。
select Department,Employee,Salary
from
(select D.name Department,E.name Employee,E.salary Salary,dense_rank() over(partition by E.departmentId order by E.salary desc) as sm
from Employee E,Department D
where E.departmentId = D.id) as newtables
where sm<=3;
newtables 就是内部新表的别名