leetcode181-Employees Earning More Than Their Managers
来源:互联网 发布:淘宝篮球鞋进货渠道 编辑:程序博客网 时间:2024/05/21 05:24
问题描述:
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+| Id | Name | Salary | ManagerId |+----+-------+--------+-----------+| 1 | Joe | 70000 | 3 || 2 | Henry | 80000 | 4 || 3 | Sam | 60000 | NULL || 4 | Max | 90000 | NULL |+----+-------+--------+-----------+
Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
+----------+| Employee |+----------+| Joe |+----------+
雇员表记录了所有雇员的信息,包括他们的经理在内。每一个雇员都有一个Id,和他的经理的Id。
给定雇员表,编写一个SQL查询找出薪水大于经理的员工姓名。对于上表来说,Joe是唯一收入大于经理的员工。
问题求解:
1、自连接
select a.name as 'Employee' from Employee a, Employee bwhere a.ManagerId=b.Id and a.salary>b.salary
2、exists
select name as 'Employee' from Employee a where exists (select Id from Employee b where a.ManagerId=b.Id and a.salary>b.salary)或者:select name as 'Employee' from Employee a where exists (select name from Employee b where a.ManagerId=b.Id and a.salary>b.salary)
3、左外连接:left join
select a.name as 'Employee' from Employee a left joinEmployee b on a.ManagerId=b.Id where a.salary>b.salary
4、内连接:inner join
select a.name as 'Employee' from Employee a inner joinEmployee b on a.ManagerId=b.Id and a.salary>b.salary
0 0
- leetcode181-Employees Earning More Than Their Managers
- Employees Earning More Than Their Managers
- Employees Earning More Than Their Managers
- Leetcode: Employees Earning More Than Their Managers
- Employees Earning More Than Their Managers
- leetcode: Employees Earning More Than Their Managers
- Employees Earning More Than Their Managers
- 【Leetcode】Employees Earning More Than Their Managers
- SQL-Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- 181 Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- MySQL-Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- 181. Employees Earning More Than Their Managers
- json
- 内核同步机制
- Linux ldd -- 查看可执行文件所依赖的动态链接库
- NSString 和NSData 转换
- 查看、分析memcached使用状态
- leetcode181-Employees Earning More Than Their Managers
- oracle中varchar和varchar2区别
- Linux lsattr --显示档案隐藏属性
- [cocos2dx笔记017]cocos2dx 2.2.6 lua的类型转换
- spring3的properties文件的开发正式环境配置
- Java 通过httpClient Post方式提交xml,并从服务端返回数据
- framework启动流程<二> init.rc 执行过程与解析
- 分布式与集群的区别
- ubuntu解压命令全览(rar)