当前位置:网站首页>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
)
边栏推荐
猜你喜欢
随机推荐
自动化运维工具Ansible(7)roles
flink onTimer定时器实现定时需求
关系型数据库-MySQL:多实例配置
FLV格式详解
flink-sql所有表连接器
Programming hodgepodge (3)
LCP 17. Quick Calculation Robot
网络大作业心得笔记
flink-sql自定义函数
Kubernetes基本入门-集群资源(二)
智能合约安全——delegatecall (1)
解决JDBC在web工程中无法获取配置文件
win云服务器搭建个人博客失败记录(wordpress,wamp)
IvNWJVPMLt
flink on yarn任务迁移
JS实现上一个、下一个、置顶、置底操作
Shell(3)条件控制语句
Commons Collections2
Linux环境下redis的下载、安装和启动(建议收藏)
自动化运维工具Ansible(2)ad-hoc