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)))
目录
相关文章
|
2月前
|
SQL 关系型数据库 MySQL
MySQL 的 WITH QUERY EXPANSION 如何使用举例
【9月更文挑战第2天】MySQL 的 WITH QUERY EXPANSION 如何使用举例
49 0
|
关系型数据库 PostgreSQL
PostgreSQL listagg within group (order by) 聚合兼容用法 string_agg ( order by) - 行列变换,CSV构造...
标签 PostgreSQL , order-set agg , listagg , string_agg , order 背景 listagg — Rows to Delimited Strings The listagg function transforms values from a g...
6184 0
|
6月前
|
SQL 关系型数据库 MySQL
Greenplum【SQL 02】ROW_NUMBER编号函数使用方法举例
Greenplum【SQL 02】ROW_NUMBER编号函数使用方法举例
143 0
|
6月前
|
SQL 关系型数据库 MySQL
SQL编程【MySQL 01】拆分列字段为行并根据类型翻译字段 > 1305 - FUNCTION x.help_topic_id does not exist 报错问题
SQL编程【MySQL 01】拆分列字段为行并根据类型翻译字段 > 1305 - FUNCTION x.help_topic_id does not exist 报错问题
80 0
|
SQL Oracle 关系型数据库
java实现oracle和mysql的group by分组功能|同时具备max()/min()/sum()/case when 函数等功能
java实现oracle和mysql的group by分组功能|同时具备max()/min()/sum()/case when 函数等功能
|
前端开发 关系型数据库 MySQL
数据合并与分隔:解析MySQL中的GROUP_CONCAT()函数
在数据库管理中,将多行数据合并成一行并以特定分隔符进行分隔,常用于生成逗号分隔的列表等情况。GROUP_CONCAT()函数就是帮助我们实现这一目标的工具。
647 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 两个字段的含义。
253 0
【MySQL从入门到精通】【高级篇】(二十四)EXPLAIN中select_type,partition,type,key,key_len字段的剖析
|
数据库
LeetCode(数据库)- Hopper Company Queries II
LeetCode(数据库)- Hopper Company Queries II
93 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
111 0
|
数据库
LeetCode(数据库)- Number of Accounts That Did Not Stream
LeetCode(数据库)- Number of Accounts That Did Not Stream
114 0