博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
181. Employees Earning More Than Their Managers【leetcode】,sql,inner join ,where
阅读量:4657 次
发布时间:2019-06-09

本文共 1015 字,大约阅读时间需要 3 分钟。

181. Employees Earning More Than Their Managers

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      |+----------+ 方法一:使用inner,效率更高
select a.Name AS  Employee  FROM Employee a inner join Employee  b ON(a.ManagerId =b.Id and a.Salary >b.Salary )

 

方法二:使用where

SELECT E.Name Employee    FROM Employee E ,Employee M    WHERE E.ManagerId=M.Id AND E.Salary>M.Salary;

 

转载于:https://www.cnblogs.com/haoHaoStudyShare/p/7441496.html

你可能感兴趣的文章
linux后台运行python程序 nohup
查看>>
吴裕雄--天生自然 高等数学学习:对面积的曲面积分
查看>>
css
查看>>
消除头文件
查看>>
Android中数据文件解析(Json解析)
查看>>
自定义seekBar设置进度条背景图片
查看>>
java容器类1:Collection,List,ArrayList,LinkedList深入解读
查看>>
16日彻底去除安卓应用的内置广告
查看>>
再谈.NET Micro Framework移植
查看>>
ssm资源配置
查看>>
斗鱼爬虫,爬取颜值频道的主播图片和名字
查看>>
【Codeforces Round #439 (Div. 2) B】The Eternal Immortality
查看>>
【MemSQL Start[c]UP 3.0 - Round 1 B】 Lazy Security Guard
查看>>
【codeforces 499C】Crazy Town
查看>>
js 逻辑与 逻辑或
查看>>
树状数组求区间最大值
查看>>
一个简单的PHP网站结构
查看>>
Redis 学习之简介及安装
查看>>
jsp简单的学习
查看>>
[LeetCode][JavaScript]Number of 1 Bits
查看>>