LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company

简介: LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company

题目链接:点击打开链接

题目大意:略。

解题思路:略。

AC 代码

WITH t AS(SELECT *, SUM(salary) OVER(PARTITION BY experience ORDER BY salary) sumn FROM Candidates),
tt AS(SELECT *, ROW_NUMBER() OVER(PARTITION BY experience ORDER BY sumn) rk FROM t),
# 解决(Senior, Junior) = (MAX, MAX) & Senior <> 0 & Junior <> 0
ttt AS(SELECT IF(t1.experience = 'Senior', t1.rk, t2.rk) Senior, IF(t2.experience = 'Junior', t2.rk, t1.rk) Junior
FROM tt t1 JOIN tt t2 ON t1.experience <> t2.experience AND t1.sumn + t2.sumn <= 70000
ORDER BY 1 DESC, 2 DESC
LIMIT 1),
# 解决(Senior, Junior) = (0, MAX)
tttt AS(SELECT MAX(rk) junior_max_rk FROM tt WHERE experience = 'Junior' AND sumn <= 70000),
# 解决(Senior, Junior) = (MAX, 0)
ttttt AS(SELECT MAX(rk) senior_max_rk FROM tt WHERE experience = 'Senior' AND sumn <= 70000)
SELECT 'Senior' experience, IF((SELECT COUNT(*) FROM ttt) = 0, 0, (SELECT * FROM ttttt)) accepted_candidates
UNION ALL
SELECT 'Junior', IF((SELECT COUNT(*) FROM ttt) = 0, (SELECT * FROM tttt), IF((SELECT * FROM ttttt) > (SELECT Senior FROM ttt), 0, (SELECT Junior FROM ttt)))
目录
相关文章
|
7月前
|
SQL 关系型数据库 MySQL
Greenplum【SQL 02】ROW_NUMBER编号函数使用方法举例
Greenplum【SQL 02】ROW_NUMBER编号函数使用方法举例
168 0
|
关系型数据库 MySQL
MySQL - ROW_NUMBER() OVER()函数用法详解(分组排序)
MySQL - ROW_NUMBER() OVER()函数用法详解(分组排序)
989 0
MySQL - ROW_NUMBER() OVER()函数用法详解(分组排序)
|
SQL 存储 算法
Mysql(四)分页&Join&Exist&count.md
Mysql(四)分页&Join&Exist&count.md
151 0
|
SQL 存储 缓存
【MySQL从入门到精通】【高级篇】(二十四)EXPLAIN中select_type,partition,type,key,key_len字段的剖析
上一篇文章我们介绍了【MySQL从入门到精通】【高级篇】(二十三)EXPLAIN的概述与table,id字段的剖析,重点对EXPLAIN命令进行了阐述,并且对table,id字段进行了剖析。这篇文章接着对EXPLAIN命令的其余字段进行解析,本文将介绍select_type,partition,type,key,key_len 字段的含义。其中:读者朋友们需要重点掌握 select_type,type 两个字段的含义。
261 0
【MySQL从入门到精通】【高级篇】(二十四)EXPLAIN中select_type,partition,type,key,key_len字段的剖析
|
数据库
LeetCode(数据库)- Hopper Company Queries II
LeetCode(数据库)- Hopper Company Queries II
99 0
LeetCode(数据库)- Hopper Company Queries II
|
数据库
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
117 0
|
数据库
LeetCode(数据库)- Number of Accounts That Did Not Stream
LeetCode(数据库)- Number of Accounts That Did Not Stream
117 0
|
数据库
LeetCode(数据库)- Hopper Company Queries III
LeetCode(数据库)- Hopper Company Queries III
89 0
|
数据库
LeetCode(数据库)- The Category of Each Member in the Store
LeetCode(数据库)- The Category of Each Member in the Store
119 0
|
数据库
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
202 0