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 ...
随机推荐
- CDN初识
CDN 全称:Content Delivery Network或Content Ddistribute Network,即内容分发网络,通过在网络各处放置节点服务器所构成的在现有的互联网基础之上的一层 ...
- vue项目全局使用axios
共有三种方法: 1.结合 vue-axios使用 首先在主入口文件main.js中引用 import axios from 'axios' import VueAxios from 'vue-axio ...
- Ajax之eval()函数
Ajax之eval()函数 <!DOCTYPE html> <html> <head lang="en"> <meta charset=& ...
- git merge最简洁
一.开发分支(dev)上的代码达到上线的标准后,要合并到 master 分支 git checkout devgit pullgit checkout mastergit merge devgit p ...
- Vue+webpack构建一个项目
1.安装CLI命令的工具 推荐用淘宝的镜像 npm install -g @vue/cli @vue/cli-init 2.使用命令构建一个名为myapp的项目 vue init webpack m ...
- 帆软中使用switch将控件的显示值“传递”给单元格
如下图,控件的实际值和显示值是我们自定义的. 当我们选择控件时,想要在某个单元格内显示控件的显示值.一般我们在单元格内直接 $控件名 可以获得控件值.比如当我们选择事故数时,我们自然不能在单元格内直 ...
- HTTP学习之HTTP基础
学习HTTP技术,首先要了解它的在web通信中有哪些特点,起到什么作用.有哪些规范.都有什么功能. HTTP的特点 HTTP使用的是一种可靠的.快速响应的数据传输协议,用户一旦发起请求,Web服务器可 ...
- (数据科学学习手札22)主成分分析法在Python与R中的基本功能实现
上一篇中我们详细介绍推导了主成分分析法的原理,并基于Python通过自编函数实现了挑选主成分的过程,而在Python与R中都有比较成熟的主成分分析函数,本篇我们就对这些方法进行介绍: R 在R的基础函 ...
- Hibernate-ORM:14.Hibernate中的命名查询
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述命名查询,所谓命名查询是什么呢? Hibernate中允许我们在xml,实体类,甚至注解的方式来编 ...
- spring、spring-data-redis整合使用
一.Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 从2010年3月15日起,Redis的开发工作由VMwa ...