当前位置:网站首页>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
边栏推荐
- Using Baidu easydl to realize chef hat recognition of bright kitchen and stove
- shared_ptr 和 make_shared 的使用
- Rust 入门指南(rustup, cargo)
- lua语言的左对齐函数(手写)
- VAE: understanding and implementation of variational self encoder
- adb remount of the / superblock failed: Permission denied
- Scrapy Spider源码分析
- 可转债概念表 x Notion 给你方便快捷的体验!
- npm安装和卸载全局包
- WPF implements MessageBox message prompt box with mask
猜你喜欢

Oracle insert数据时字符串中有‘单引号问题

英文翻译阿拉伯语-批量英文翻译阿拉伯语工具免费

宝塔面板搭建小说CMS管理系统源码实测 - ThinkPHP6.0

Servlet learning notes

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

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

Basic concept and essence of Architecture

Business visualization - let your flowchart "run" (4. Actual business scenario test)

云计算笔记part.1——系统管理

基于QTGUI图像界面的空战游戏设计
随机推荐
Thoroughly understand bit operations - shift left, shift right
The peak rate exceeds 2gbps! Qualcomm first passed 5g millimeter wave MIMO OTA test in China
Convertible bond concept table x notation gives you a convenient and fast experience!
adb remount of the / superblock failed: Permission denied
MySQL8 Encrypting InnoDB Tablespaces
The United States will provide $25billion in subsidies to encourage chip manufacturers such as Intel to move back to production lines
Amazon launched Amazon one palm payment system, and the contactless palm vein recognition market is expected to explode
Force buckle 1331. Array serial number conversion
助力面板行业创新,FPGA将成屏厂TCON最佳选择?
Pytoch: quickly find the main diagonal elements and non diagonal elements of NxN matrix
Rust 入门指南(crate 管理)
WPF implements MessageBox message prompt box with mask
Cell review: single cell methods in human microbiome research
Preliminary learning function (3rd blog)
初步学习函数(第3篇博客)
为什么在telnet登入界面下没有日志输出?
亚马逊推出Amazon One手掌支付系统,非接触式掌静脉识别市场有望爆发
How openocd directly downloads programs to STM32 board through stlink (solved)
Test Development Notes
德国、葡萄牙均宣布不会禁用华为5G设备,但德国会设定严格限制条件!