代码拉取完成,页面将自动刷新
# $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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。