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 |
+----------+ 要求:查询出表中工资比经理高的员工姓名 查询一:

CREATE TABLE `employee` (
`id` tinyint(3) unsigned DEFAULT NULL,
`e_name` varchar(20) DEFAULT NULL,
`salary` decimal(10,2) DEFAULT NULL,
`m_id` tinyint(3) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

SELECT em1.e_name
FROM(SELECT id,e_name,salary,m_id FROM employee_1 WHERE m_id IS NOT NULL) em1
INNER JOIN employee_1 em2 ON em1.m_id=em2.id
WHERE em1.salary>em2.salary

查询二:

SELECT e1.e_name
FROM employee_1 e1
INNER JOIN employee_1 e2 ON e1.m_id=e2.id
WHERE e1.salary>e2.salary

												

[LeetCode]-DataBase-Employees Earning More Than Their Managers的更多相关文章

  1. LeeCode(Database)-Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  2. Leetcode 181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  3. 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, ...

  4. leetcode 181 Employees Earning More Than Their Managers 不会分析的数据库复杂度

    https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ 老师上课没分析这些的复杂度, ...

  5. LeetCode 181. Employees Earning More Than Their Managers (超过经理收入的员工)

    题目标签: 题目给了我们一个 员工表,包括经理.员工会有经理的id. 这里可以重复 利用两次 表格,表格a, 表格b,当a 员工的经理id  等于 b员工时候,在从中找到员工工资大于经理的.具体看co ...

  6. LeetCode SQL:Employees Earning More Than Their Managers

    # Write your MySQL query statement below SELECT a.Name FROM Employee AS a INNER JOIN Employee AS b O ...

  7. [LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  8. LeetCode - Employees Earning More Than Their Managers

    Description: The Employee table holds all employees including their managers. Every employee has an ...

  9. LeetCode——Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  10. [SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers

    SQL架构 Create table If Not Exists Employee (Id ), Salary int, ManagerId int) Truncate table Employee ...

随机推荐

  1. PHP手册在7.1迁移页面给出了替代方案,就是用OpenSSL取代MCrypt.

    /**  * [AesSecurity aes加密,支持PHP7.1]  */ class AesSecurity {     /**      * [encrypt aes加密]      * @p ...

  2. Gantt与PERT图区别

    甘特图也就做进度管理图.他是一种简单的水平条形图,它以日历为基准描述项目任务,水平轴表示日历时间线,每一个线条表示一个任务,任务名称垂直的列在左边列中,图中的线条的起点和终点对应水平轴上的时间,分别表 ...

  3. visual studio git 忽略文件配置模板

    ## Ignore Visual Studio temporary files, build results, and## files generated by popular Visual Stud ...

  4. 剑指offer 剪绳子

    题目描述 给你一根长度为n的绳子,请把绳子剪成m段(m.n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]xk[1]x...xk[m]可能 ...

  5. curry&unCurry函数

    unCurry函数与curry函数区别:curry化函数:固定部分参数,返回一个接受剩余参数的新函数,目的是为了缩小适用范围,创建一个针对性更强的函数. unCurry化函数:扩大适用范围,创建一个应 ...

  6. 雪花算法生成ID

    前言我们的数据库在设计时一般有两个ID,自增的id为主键,还有一个业务ID使用UUID生成.自增id在需要分表的情况下做为业务主键不太理想,所以我们增加了uuid作为业务ID,有了业务id仍然还存在自 ...

  7. 使用CXF开发WebService程序的总结(三):创建webservice客户端

    1.创建一个maven子工程 ws_client,继承父工程 1.1 修改父工程pom配置 <modules> <module>ws_server</module> ...

  8. Idea多模块工程创建——继承、聚合

    一.工程介绍 淘淘网上商城是一个综合性的B2C平台,类似京东商城.天猫商城.会员可以在商城浏览商品.下订单,以及参加各种活动. 管理员.运营可以在平台后台管理系统中管理商品.订单.会员等. 客服可以在 ...

  9. ms17010批量扫描备忘

    安装一些依赖: dpkg --add-architecture i386 && apt-get update && apt-get install wine32 rm ...

  10. ThinkCMF5.1虚拟机下安装的问题,已成功

    官方的解决方案:https://www.kancloud.cn/thinkcmf/faq/1197179 按它的提示,发现阿里云的虚拟主机htdoc同级的目录没有上传权限. 只能把“ThinkCMF文 ...