当前位置:网站首页>Leetcode day3 employees who exceed the manager's income
Leetcode day3 employees who exceed the manager's income
2022-07-28 19:43:00 【wyqgg123】
181. Employees who earn more than their managers
The difficulty is simple
SQL framework
Employee Table contains all employees , Their manager also belongs to the staff . Every employee has one Id, In addition, there is a list of managers corresponding to employees Id.
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
Given Employee surface , Write a SQL Inquire about , This query can get the names of employees who earn more than their managers . In the table above ,Joe It's the only employee who earns more than his manager .
+----------+
| Employee |
+----------+
| Joe |
+----------+
Answer key :
The implementation of this problem is relatively simple , You only need a self table connection to complete this operation
1、 First, query all the data connected from the table .
select * from Employee a1
left join Employee a2
on a1.Managerid = a2.id
The operation results are shown in the following table
| a1.id | a1.name | a1.salary | a1.ManagerId | a2.id | a2.name | a2.salary | a2.ManagerId |
|---|---|---|---|---|---|---|---|
| 1 | Joe | 70000 | 3 | 3 | Sam | 60000 | Null |
| 2 | Henry | 80000 | 4 | 4 | Max | 90000 | Null |
| 3 | Sam | 60000 | Null | Null | Null | Null | Null |
| 4 | Max | 90000 | Null | Null | Null | Null | Null |
2、 We just need to judge and find out a1.salary The value is greater than a2.salary The value of the a1.name That's all right.
select a1.Name as Employee from Employee a1
left join Employee a2
on a1.Managerid = a2.id
where a1.Salary > a2.Salary
Running results :
Employee : Joe
边栏推荐
- Rust 入门指南(modules 和工程结构)
- Business visualization - let your flowchart "run" (4. Actual business scenario test)
- Cloud computing notes part.2 - Application Management
- andorid系统layout、values、drawable适配
- Preliminary learning function (3rd blog)
- Sword finger offer II 109. unlock the password lock
- 英文翻译意大利语-批量英文翻译意大利语工具免费
- 读了三年论文,我今天才学会阅读摘要
- With the help of panel industry innovation, will FPGA become the best choice for TCON?
- 中国首枚芯片邮票面世:内置120um超薄NFC芯片
猜你喜欢

英语文章翻译-英语文章翻译软件-免费批量翻译

【微信小程序开发】页面导航与传参

Using Baidu easydl to realize chef hat recognition of bright kitchen and stove

个人博克系统登录点击图形验证码的集成与实现

What parameters should be passed in calling integer or character array functions

Cell综述:人类微生物组研究中的单细胞方法

Rust Getting Started Guide (crite Management)

Pagoda panel construction novel CMS management system source code measurement - thinkphp6.0

你知道雨的类型有几种?

How does app automated testing achieve H5 testing
随机推荐
英文翻译阿拉伯语-批量英文翻译阿拉伯语工具免费
为什么在telnet登入界面下没有日志输出?
First blog
MySQL 8 creates master-slave replication based on Clone
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
idea properties文件显示\u不显示中文的解决
Redis master-slave architecture (how to calculate sizeof function)
Servlet学习笔记
Iclr21 (classification) - future classic "vit" an image is worth 16x16 words (including code analysis)
读了三年论文,我今天才学会阅读摘要
Preliminary learning function (3rd blog)
11. Learn MySQL union operator
时间转日期的sql语句应该怎么写?
andorid系统layout、values、drawable适配
Business visualization - let your flowchart "run" (4. Actual business scenario test)
Rust 入门指南(modules 和工程结构)
source insight项目导入和使用教程
Redis笔记
测试开发备忘
这个客制化键盘,秀翻我了~