1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-2010.test 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 3年前 . fix lc-2010.test
# $2010. 职员招聘人数 II
# https://leetcode-cn.com/problems/the-number-of-seniors-and-juniors-to-join-the-company-ii/
# SQL架构
Create table If Not Exists Candidates (employee_id int, experience ENUM('Senior', 'Junior'), salary int);
Truncate table Candidates;
insert into Candidates (employee_id, experience, salary) values ('1', 'Junior', '10000');
insert into Candidates (employee_id, experience, salary) values ('9', 'Junior', '15000');
insert into Candidates (employee_id, experience, salary) values ('2', 'Senior', '20000');
insert into Candidates (employee_id, experience, salary) values ('11', 'Senior', '16000');
insert into Candidates (employee_id, experience, salary) values ('13', 'Senior', '50000');
insert into Candidates (employee_id, experience, salary) values ('4', 'Junior', '40000');
# Write your MySQL query statement below
with seniortotal as (
select
employee_id,
sum(salary) over (
order by
salary
) as totalone
from
Candidates
where
experience = 'Senior'
),
seniornumber as (
select
max(totalone) totals
from
seniortotal
where
totalone <= 70000
),
juniortotal as (
select
employee_id,
sum(salary) over (
order by
salary
) as totaltwo
from
Candidates
where
experience = 'Junior'
)
select
employee_id
from
seniortotal
where
totalone <= 70000
union
all
select
employee_id
from
juniortotal,
seniornumber
where
totaltwo < 70000 - ifnull(totals, 0);
# clean-up
drop table Candidates;
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

搜索帮助