Department Top Three Salaries
2016-03-22 14:42
375 查看
表内自连接,得到rank前三的记录
https://leetcode.com/problems/department-top-three-salaries/
第一种:
第二种:
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 E1 INNER JOIN (SELECT DISTINCT Salary,DepartmentId FROM Employee) E2 ON E1.DepartmentId=E2.DepartmentId AND E1.Salary<=E2.Salary GROUP BY E1.id,E1.Name,E1.Salary,E1.DepartmentId) C WHERE C.RANK<4) A INNER 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;
相关文章推荐
- [BZOJ1018][SHOI2008]堵塞的交通traffic(线段树维护连通性)
- 设计师の学习网站
- Linux/include/uapi/linux/input.h
- apache通过域名实现对项目的区分
- hadoop学习之-hive-数据模型
- 乱码问题tomcat
- squid代理服务器搭建及配置
- Shell技巧
- Spring学习笔记(十九):关于tomcat运行一直出错的问题
- linux下载中心
- linux设备树的建立过程
- linux device tree源代码解析
- Docker常用命令
- 结合VTS和BACnet协议栈源码分析Write Property读属性
- 好看的网站
- 树形结构的维护:BZOJ 3991: [SDOI2015]寻宝游戏
- linux centos6.5 rpm安装mysql5.7
- Kubernetes系统架构简介
- LinuxMint定制底部任务栏
- IMAP和POP3的区别?