Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-0184.test 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-04-17 17:42 +08:00 . 184-580-626-1294-1501 (5)
# 184. 部门工资最高的员工
# https://leetcode-cn.com/problems/department-highest-salary/
# SQL架构
Create table If Not Exists Employee (id int, name varchar(255), salary int, departmentId int);
Create table If Not Exists Department (id int, name varchar(255));
Truncate table Employee;
insert into Employee (id, name, salary, departmentId) values ('1', 'Joe', '70000', '1');
insert into Employee (id, name, salary, departmentId) values ('2', 'Jim', '90000', '1');
insert into Employee (id, name, salary, departmentId) values ('3', 'Henry', '80000', '2');
insert into Employee (id, name, salary, departmentId) values ('4', 'Sam', '60000', '2');
insert into Employee (id, name, salary, departmentId) values ('5', 'Max', '90000', '1');
Truncate table Department;
insert into Department (id, name) values ('1', 'IT');
insert into Department (id, name) values ('2', 'Sales');
# Write your MySQL query statement below
select
d.name as Department,
e.name as Employee,
e.salary as Salary
from
Employee e
join Department d on e.departmentId = d.id
where
(e.departmentId, e.salary) in (
select
departmentId,
max(salary)
from
Employee
group by
departmentId
);
# clean-up
drop table Employee;
drop table Department;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助