leetcode SQL题目好好写一下

leetcode 184

部门工资最高的
# Write your MySQL query statement below


SELECT e1.name as Employee, e1.salary as Salary, d.name as Department
from employee e1 INNER join department d
on e1.departmentId = d.id
WHERE 1 >=
    (
        SELECT COUNT(distinct (e2.salary)) from employee e2 WHERE e2.salary >= e1.salary and e2.departmentId = d.id
    ) ORDER BY d.name, e1.salary DESC ;


leetcode 185
部门工资最高的三个人
# Write your MySQL query statement below

select d.Name Department ,e1.Name Employee,e1.Salary Salary 
from Employee e1
inner join Department d on e1.DepartmentId= d.Id
where 3 >= (
           select count(distinct(e2.Salary)) from Employee e2 where e2.Salary >=e1.Salary and e2.DepartmentId=d.Id
       ) order by d.Name,e1.Salary Desc;



全部评论

相关推荐

Dream_coding:你是不是只投大厂了
点赞 评论 收藏
分享
02-25 11:29
产品经理
牛客444597598号:兄弟 我只能说如果想找产品经理这种简历 基本就是毕业失业了 你这连实习都找不到的 简历跟产品经理一点都没有关系,你可以去搜搜产品的模版吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务