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. mysql自增主键字段重排

    不带外键模式的 mysql 自增主键字段重排 1.备份表结构 create table table_bak like table_name; 2.备份表数据 insert into table_bak ...

  2. postgresql 相关操作

    1.root 用户,执行 service postgresql restart service postgresql start  --启动 2.查看数据库状态 /etc/init.d/postgre ...

  3. Linux FTP的安装与权限配置

    ftp安装部分,操作步骤如下: 1.切换到root用户 2.查看是否安装vsftp,我这个是已经安装的. [root@localhost vsftpd]# rpm -qa |grep vsftpd v ...

  4. Android 关于悬浮窗权限的问题

    正常情况下的处理: dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)以及在清单文件中添加 <use ...

  5. tomcat中部署多个项目,webAppRootKey 参数配置

    在一个tomcat中部署多个项目时,需要在每个项目的web.xml中配置webAppRootKey参数,如下: <context-param> <param-name>webA ...

  6. 测试 windows 发布日志

    <script>alert("hellow world")</script>

  7. web框架-(五)Ajax

    Ajax即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术,AJAX = 异步 JavaScript和X ...

  8. 十一、S3C2440 裸机 — GPIO

    11.1 GPIO 介绍 11.1.1 GPIO 管脚 GPIO 即是输入输出端口,S3C2440A 包含了 130 个多功能输入/输出口引脚并且它们为如下显示的八个端口: 端口 A(GPA):25 ...

  9. Python之网路编程之socket简单介绍

    一.网络协议 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构(互联网中处处是C/S架构):B/S架构也是C/S架构的一种,B/S是浏览器/服务器 C/S架构与socket的关系: ...

  10. python 后台 安装 富文本编辑

    前言 当然需要安装一些后台只能输入一些文本编辑器,不然这样多少不美观呀 当然python 有 safe 可以把后台的标签转换 , 还有 striptags   这个是换成html 格式的,但不会加粗或 ...