V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Bruin
V2EX  ›  程序员

关于 leetcode mysql 问题:部门工资前三高的所有员工

  •  
  •   Bruin · Oct 16, 2019 · 2018 views
    This topic created in 2393 days ago, the information mentioned may be changed or developed.

    题目:部门工资前三高的所有员工

    我的 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,提交审核就挂了!不知道问题在哪儿!

    2 replies    2019-10-17 07:54:40 +08:00
    c6h6benzene
        1
    c6h6benzene  
       Oct 16, 2019 via Android
    原谅我的第一反应是 Row_Number 或者 Rank
    wd
        2
    wd  
       Oct 17, 2019 via iPhone
    mysql 支持 window function 吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2553 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 11:02 · PVG 19:02 · LAX 04:02 · JFK 07:02
    ♥ Do have faith in what you're doing.