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;



全部评论

相关推荐

03-24 00:03
门头沟学院 Java
恶龙战士:实习经历写的不行,需要改,不管是改成主业务还是主技术都可以
点赞 评论 收藏
分享
04-08 13:31
已编辑
门头沟学院 前端工程师
D0cC:京东营收1万多亿人民币,阿里9000多亿,虽然他俩利润都没腾讯和字节多,但是很恐怖了啊,负担了多少打工人的薪水
投递拼多多集团-PDD等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务