当前位置:网站首页>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
)
边栏推荐
猜你喜欢
随机推荐
bind和function
将两个DataTable合并——DataTable.Merge 方法
对象存储-分布式文件系统-MinIO-2:服务端部署
Redis持久化方式RDB和AOF详解
flink-sql所有语法详解
Linux环境下redis的下载、安装和启动(建议收藏)
Embedded system driver primary [4] - under the basis of character device driver _ concurrency control
Code Refactoring: For Unit Testing
lambda函数用法总结
剑指 Offer 2022/7/9
Swoole学习(一)
MediaCodec支持的类型
flink-sql所有表格式format
二月、三月校招面试复盘总结(二)
字符串常用方法
计算属性的作用及使用?
二月、三月校招面试复盘总结(一)
7.15 Day21---MySQL----Index
程序员的财富观
Lombok的一些使用心得