题目:部门工资前三高的所有员工
我的 sql 如下
select t.Name as Department, Employee.Name as Employee, Employee.Salary from Employee ,
(
SELECT *, IFNULL((
SELECT DISTINCT(salary) from Employee, (select @i :=0, @pre := -1) t
where Employee.DepartmentId = Department.id
HAVING ( @i := @i + (@pre != (@pre := salary))) = 3
ORDER BY salary desc
), 0) as salary from Department
) as t
where t.id = Employee.DepartmentId and Employee.Salary >= t.Salary
order by t.id asc, Employee.Salary desc;
本地 sql 执行结果 ok,leetcode 执行代码也 ok,提交审核就挂了!不知道问题在哪儿!
1
c6h6benzene 2019-10-16 18:54:16 +08:00 via Android
原谅我的第一反应是 Row_Number 或者 Rank
|
2
wd 2019-10-17 07:54:40 +08:00 via iPhone
mysql 支持 window function 吗?
|