DataBase -- Employees Earning More Than Their Managers My Submissions Question
Question:
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 |
+----------+
Analysis:
Employee表格包含公司里所有的员工,包括他们的经理。每个员工都有一个员工ID和一个经理ID。
给出Employee表格,写一个SQL语句,找出工资比他的经理还高的员工。例如在上面的例子中,只有Joe满足该情况。
最后给出什么则select后面接什么,如果遇到比较的,则应该选择使用两个表格。
Answer:
select e1.Name from Employee e1, Employee e2
where e2.Id = e1.ManagerId and e1.Salary > e2.Salary
DataBase -- Employees Earning More Than Their Managers My Submissions Question的更多相关文章
- LeeCode(Database)-Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- [LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- Leetcode 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- [SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers
SQL架构 Create table If Not Exists Employee (Id ), Salary int, ManagerId int) Truncate table Employee ...
- 【SQL】181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- LeetCode - Employees Earning More Than Their Managers
Description: The Employee table holds all employees including their managers. Every employee has an ...
- 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- LeetCode——Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
随机推荐
- 设置Vim编辑器里Tab的长度,行号
使用Vim编辑器写脚本时,经常会遇到多重循环语句,习惯上会用tab键来补齐.这时设置tab键占用的长度,可以调节界面的松紧度,使其达到令人满意的效果. 在针对个别用户和所有用户来设置时,与编辑SSH相 ...
- Jenkins 添加节点 java web方式
环境说明: 主节点:windows server 从节点:两台linux 1. windows server安装jenkins就不多说了,直接添加节点配置如下 2.全局安全配置,指定确认的端口后,记得 ...
- 01-HTML深入
1.1 浏览器的工作原理 把一些标签解析成用户可视化的页面 1.2 HTML中的标签与元素 在HTML中以<xx>开始,以</xx>结束,比如<html>< ...
- 用C#实现WEB代理服务器
用C#实现Web代理服务器 代理服务程序是一种广泛使用的网络应用程序.代理程序的种类非常多,根据协议不同可以分成HTTP代理服务程序.FTP代理服务程序等,而运行代理服务程序的服务器也就相应称为HTT ...
- php Trait的使用
1.php中的trait是啥? 看上去既像类又像接口,其实都不是,Trait可以看做类的部分实现,可以混入一个或多个现有的PHP类中,其作用有两个:表明类可以做什么:提供模块化实现.Trait是一种代 ...
- SHELL里执行HIVE导出文件处理成CSV文件
#!/bin/bash #用途: #.当前目录的txt文件批量转csv #.制表符转逗号分隔符 #.NULL去除 #.删除WARN警告 for i in `ls ./*.txt` do sed -e ...
- 9.1 IIC驱动源码分析
学习目标:分析linux内核源码下的i2c总线驱动 drivers/i2c/busses/i2c-s3c2410.c 和 driver/i2c/chips/eeprom.c 设备驱动: 一.i2c驱动 ...
- javascript的优美与鸡肋
--总结来自:<javascript语言精粹> 任何语言都有其优美的地方和其鸡肋的地方.避归一些语言的糟粕,能相应的降低bug出现的几率. 优美处: 函数是头等对象 基于原型继承的动态对象 ...
- 从循环里面用QPixmap new对象很耗时联想到的
1.在循环里面用QPixmap new图片对象延迟很高,这个是通过打时间日志得出的,深层原因还不清楚: 2.自制的图片浏览器在初始化的时候会初始化自己的一个图片列表,所以要用到上面的描述.所有图片的初 ...
- YAGNI 声明
1.YAGNI介绍 YAGNI 全名是 You aren't Going to Need It,在你设计草案的初稿中,应该努力使用最简单可以工作的事物,直至程序的某个方面要求你添加额外的特性. 2.思 ...