Department Top Three Salaries
来源:互联网 发布:海外淘软件 编辑:程序博客网 时间:2024/06/05 17:53
表内自连接,得到rank前三的记录
https://leetcode.com/problems/department-top-three-salaries/
第一种:
SELECT D.Name AS Department,A.Employee,A.Salary FROM(SELECT C.DepartmentId,C.Name AS Employee,C.Salary FROM(SELECT E1.id,E1.Name,E1.Salary,E1.DepartmentId,COUNT(1) AS RANK FROM Employee E1INNER JOIN (SELECT DISTINCT Salary,DepartmentId FROM Employee) E2ON E1.DepartmentId=E2.DepartmentId AND E1.Salary<=E2.SalaryGROUP BY E1.id,E1.Name,E1.Salary,E1.DepartmentId) C WHERE C.RANK<4) AINNER JOIN Department D ON D.Id=A.DepartmentId
第二种:
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
- Department Top Three Salaries
- Department Top Three Salaries
- [leetcode] Department Top Three Salaries
- LeetCode Department Top Three Salaries
- 185. Department Top Three Salaries
- [LeetCode][Database]Department Top Three Salaries
- LeetCode_OJ【185】Department Top Three Salaries
- 题目9:MySQL---------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
- leetcode数据库sql之Department Top Three Salaries
- [LeetCode] Department Highest & Top 3 Salary - SQL
- You should be the top dog in your department and always keep an eye on the outside world.
- Android线程销毁
- H——H
- php5.5.12+redis2.6 Windwos安装下安装
- iOS开发调试技巧总结
- P与NP问题的简单解释
- Department Top Three Salaries
- 微信获取accesstoken以及openID
- UVa 327 - Evaluating Simple C Expressions
- NoNodeAvailableException[None of the configured nodes are available
- android L和android M的区别
- FFMPEG 截取RTMP直播流图片命令
- Android 避免Activity重复创建 一次finish()返回上个页面
- 自定义ViewGroup的使用
- makefile中的notdir,wildcard和patsubst