当前位置:网站首页>SQL练习 2022/7/3
SQL练习 2022/7/3
2022-08-04 05:28:00 【Provence°_博】
SQL练习 2022/7/3
184. 部门工资最高的员工
代码思路
- 嵌套查询,先查部门的最高工资,然后联合表再查人
select
department.name as Department,
employee.name as Employee,
employee.salary as Salary
from
employee left join department
on
department.id=employee.departmentId
where
(departmentId,salary) in
(select
departmentId ,max(salary)
from employee
group by departmentId)
- 开窗函数
利用dense_rank() over()函数根据部门分区得出排名
select
Department,Employee,salary
from
(select
d.name Department , e.name Employee,e.salary,dense_rank() over(partition by departmentId order by salary desc)rn
from Employee e,Department d
where e.departmentId = d.id)
where rn=1
196. 删除重复的电子邮箱
题干
代码思路
- 简单查询
delete p1.*
from person p1,person p2
where p1.email=p2.email and p1.id>p2.id
delete from person
where person.id in
(
select id
from
(select p1.id
from person p1,person p2
where p1.email=p2.email and p1.id>p2.id)a
)
边栏推荐
猜你喜欢
随机推荐
JNI基本使用
NFT市场以及如何打造一个NFT市场
剑指 Offer 2022/7/12
IvNWJVPMLt
flink onTimer定时器实现定时需求
音视频相关基础知识与FFmpeg介绍
Swoole学习(一)
程序员的财富观
Kubernetes集群安装
纳米级完全删除MYSQL5.7以及一些吐槽
完美解决keyby造成的数据倾斜导致吞吐量降低的问题
个人练习三剑客基础之模仿CSDN首页
FLV格式详解
对象存储-分布式文件系统-MinIO-3:MinIo Client(mc)
k9s-终端UI工具
智能合约安全——delegatecall (2)
攻防世界MISC———Dift
实际开发中,如何实现复选框的全选和不选
自动化运维工具Ansible(6)Jinja2模板
flink-sql所有语法详解








