当前位置:网站首页>leetcode day3 超过经理收入的员工
leetcode day3 超过经理收入的员工
2022-07-28 17:47:00 【wyqgg123】
181. 超过经理收入的员工
难度简单
SQL架构
Employee 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
给定 Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。
+----------+
| Employee |
+----------+
| Joe |
+----------+
题解:
本题实现比较简单,只需要一个自表连接就可以完成该操作
1、首先查询全部自表连接的数据。
select * from Employee a1
left join Employee a2
on a1.Managerid = a2.id
运行结果如下表格
| 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、我们只需要进行判断查询出来a1.salary的值大于a2.salary的值的a1.name就可以了
select a1.Name as Employee from Employee a1
left join Employee a2
on a1.Managerid = a2.id
where a1.Salary > a2.Salary
运行结果:
Employee : Joe
边栏推荐
- Sword finger offer II 109. unlock the password lock
- 冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
- andorid系统layout、values、drawable适配
- VAE: understanding and implementation of variational self encoder
- BLDC 6-step commutation simulink
- [solved] ac86u ml revision firmware virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements
- SaltStack配置管理
- 使用SaltStack自动化部署Zabbix
- 开盘暴涨215%!国产信号链芯片企业芯海科技登陆科创板
- Rust Getting Started Guide (rustup, cargo)
猜你喜欢

冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题

navicate修改数据库名的方式

远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作

Sword finger offer II 109. unlock the password lock

source insight项目导入和使用教程

使用SaltStack自动化部署LNMP

文章翻译软件-批量免费翻译软件支持各大翻译接口

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

How openocd directly downloads programs to STM32 board through stlink (solved)

SaltStack系统初始化
随机推荐
After reading the thesis for three years, I learned to read the abstract today
Rust Getting Started Guide (crite Management)
Test Development Notes
Pytoch: implementation of crossentropyloss and labelsmoothing
Force buckle 1331. Array serial number conversion
毕马威中国:证券基金经营机构信息技术审计项目发现洞察
这个客制化键盘,秀翻我了~
[notes] Apocalypse: list of practical experience and reflection of product managers
Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters
诺基亚扩大与英国电信的5G协议,将成其最大无线接入设备供应商
SaltStack系统初始化
MATLAB实现的图像分割之边缘检测和连接
Rust 入门指南(rustup, cargo)
BLDC 6-step commutation simulink
英语文章翻译-英语文章翻译软件-免费批量翻译
英文翻译葡萄牙语-批量英文转换葡萄牙语-各种语言免费互译转换
Swing事件处理的过程是怎样的?
【笔记】《启示录》:产品经理的实践经验与反省清单
MySQL性能测试工具sysbench学习
leetcode day4 部门工资最高的员工