当前位置:网站首页>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 入门指南(crate 管理)
- lua语言的左对齐函数(手写)
- [网络]跨区域网络的通信学习IPv4地址的分类和计算
- When CNN meets transformer cmt:revolutionary neural networks meet vision transformers
- Failed to install app-debug.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
- NetCoreAPI操作Excel表格
- 基于QTGUI图像界面的空战游戏设计
- Iclr21 (classification) - future classic "vit" an image is worth 16x16 words (including code analysis)
- 英文翻译西班牙语-批量英文翻译西班牙工具免费
- 11. Learn MySQL union operator
猜你喜欢

并发程序设计,你真的懂吗?

Basic concept and essence of Architecture

English article translation - English article translation software - free batch translation

Pytoch: implementation of crossentropyloss and labelsmoothing

BLDC 6-step commutation simulink

Rust Getting Started Guide (modules and engineering structures)

英文翻译葡萄牙语-批量英文转换葡萄牙语-各种语言免费互译转换

彻底理解位运算——左移、右移

Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters

Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network
随机推荐
毕马威中国:证券基金经营机构信息技术审计项目发现洞察
Pytoch: implementation of crossentropyloss and labelsmoothing
Servlet learning notes
English article translation - English article translation software - free batch translation
Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
个人博克系统登录点击图形验证码的集成与实现
WPF 实现带蒙版的 MessageBox 消息提示框
What parameters should be passed in calling integer or character array functions
第一次写博客
博途1200/1500PLC上升沿下降沿指令编程应用技巧(bool数组)
远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
stc12c5a60s2功能说明(STC12C5A60S2默认触发)
读了三年论文,我今天才学会阅读摘要
Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network
Search problems and technologies
Rust 入门指南(crate 管理)
andorid系统layout、values、drawable适配
leetcode day5 删除重复的电子邮箱
BLDC 6-step commutation simulink