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 |
+----------+

这种单表比较条件,一般都是表内进行join操作.

参照此思路,解题如下所示:

# Write your MySQL query statement below
SELECT
a.Name AS Employee
FROM Employee a, Employee b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary;

运行效率在可以接受的范围,此外语句也较为清晰便于维护.

最新文章

  1. redis事务详解
  2. 转载文章----C#基础概念
  3. 线段树——Ultra-QuickSort
  4. Jquery easyui的validatebox控件和正则表达式
  5. 使用codeblock实现JNI开发-2016.01.31
  6. 使用ssh公钥密钥自动登陆linux服务器
  7. levelDB缓存实现
  8. JObject对json的操作
  9. vue集成环信IM
  10. Windows文件系统
  11. u3d内嵌H5游戏 设置cookie
  12. 重磅:Spring Boot 2.0 正式发布!
  13. MongoDB shell 介绍
  14. Emacs常用基本操作
  15. Git合并最近的commit
  16. linux(ubuntu)下安装phantomjs
  17. UVaLive 3357 Pinary (Fib数列+递归)
  18. C++ —— 重载、覆盖和隐藏
  19. pwd、ln和重定向命令
  20. Beta冲刺一《WAP团队》

热门文章

  1. Mysql双主加Keepalived+读写分离
  2. 删除带外键的表【foreign key constraint fails】报错
  3. Python散列类型和运算符
  4. [PHP] 运维新增服务器导致的附件上传失败问题
  5. fiddler---Fiddler弱网测试
  6. I2C硬件与模拟的区别
  7. CUDA -- 规约求矩阵的行和
  8. 04webpack--webpack-dev-server 时时跟新
  9. redis入门与应用
  10. pytest-2:allure 的安装、使用