LeetCode Department Top Three Salaries
来源:互联网 发布:淘宝卖家的支付宝红包 编辑:程序博客网 时间:2024/06/06 01:09
The Employee
table holds all employees. Every employee has an Id, and there is also a column for the department Id.
+----+-------+--------+--------------+| Id | Name | Salary | DepartmentId |+----+-------+--------+--------------+| 1 | Joe | 70000 | 1 || 2 | Henry | 80000 | 2 || 3 | Sam | 60000 | 2 || 4 | Max | 90000 | 1 || 5 | Janet | 69000 | 1 || 6 | Randy | 85000 | 1 |+----+-------+--------+--------------+
The Department
table holds all departments of the company.
+----+----------+| Id | Name |+----+----------+| 1 | IT || 2 | Sales |+----+----------+
Write a SQL query to find employees who earn the top three salaries in each of the department. For the above tables, your SQL query should return the following rows.
+------------+----------+--------+| Department | Employee | Salary |+------------+----------+--------+| IT | Max | 90000 || IT | Randy | 85000 || IT | Joe | 70000 || Sales | Henry | 80000 || Sales | Sam | 60000 |+------------+----------+--------+
select d1.name as department, e1.name as employee, e1.salary as salary from Department d1, Employee e1 where ( select count(distinct e2.salary) from Employee e2 where e2.salary > e1.salary and e2.departmentid = e1.departmentid) < 3 and d1.id = e1.departmentid;
0 0
- [leetcode] Department Top Three Salaries
- LeetCode Department Top Three Salaries
- Department Top Three Salaries
- Department Top Three Salaries
- [LeetCode][Database]Department Top Three Salaries
- LeetCode 185. Department Top Three Salaries
- leetcode-database-185. Department Top Three Salaries
- leetcode 185. Department Top Three Salaries
- 【leetcode Database】185. Department Top Three Salaries
- leetcode 185. Department Top Three Salaries
- leetcode 184,185 Department Top Three Salaries/HIGHEST Salaries
- 【LeetCode】Department Highest Salary && Department Top Three Salaries
- 185. Department Top Three Salaries
- leetcode数据库sql之Department Top Three Salaries
- LeetCode_OJ【185】Department Top Three Salaries
- 题目9:MySQL---------Department Top Three Salaries
- [LeetCode] Department Highest & Top 3 Salary - SQL
- LeetCode:Department Highest Salary
- [LeetCode]House Robber
- 【C语言】用结构体数组指针完成:有三个学生信息,存放在结构体数组中,要求输出全部信息
- Fileupload上传文件修改文件名字
- 两个隔离的网卡配置
- xpages客户端安装插件demo
- LeetCode Department Top Three Salaries
- TCP如何保证它的通信的可靠性
- Struct 和 Union区别
- Hibernate注解详解
- 【学习】Java的反射机制
- Android NDK开发之入门教程
- Scramble String--LeetCode
- swift学习记录(enumerate)
- jquery【插件】 pagination使用