当前位置: 首页 > news >正文

MySQL高阶2010-职员招聘人数2

目录

题目

准备数据

分析数据

总结


题目

一家公司想雇佣新员工。公司的工资预算是 $70000 。公司的招聘标准是:

  1. 继续雇佣薪水最低的高级职员,直到你不能再雇佣更多的高级职员。
  2. 用剩下的预算雇佣薪水最低的初级职员。
  3. 继续以最低的工资雇佣初级职员,直到你不能再雇佣更多的初级职员。

编写一个解决方案,查找根据上述条件雇用职员的 ID。
按 任意顺序 返回结果表。

准备数据

Create table If Not Exists Candidates (employee_id int, experience ENUM('Senior', 'Junior'), salary int)Truncate table Candidatesinsert 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')

分析数据

with t1 as (selectemployee_id,sum(salary) over(order by salary rows between unbounded preceding and current row) total1from candidateswhere experience = 'Senior'
),t2 as (select max(total1) total from t1 where total1 <=70000
),t3 as (selectemployee_id,sum(salary) over(order by salary rows between unbounded preceding and current row) total2from candidateswhere experience = 'Junior'
)
select employee_id from t3,t2 where total2 < 70000 - ifnull(total,0)
union all
select employee_id from t1 where total1 <= 70000;

总结

与2004题不同的是,2004求个数,而2010是求employee_id.

http://www.lryc.cn/news/451827.html

相关文章:

  • 【Java】—— 集合框架:Collection接口中的方法与迭代器(Iterator)
  • 华证ESG工具变量(2009-2022年)
  • Linux date命令(用于显示和设置系统的日期和时间,不仅可以显示时间,还能进行复杂的时间计算和格式化)
  • 高中教辅汇总【35GB】
  • 树莓派 AI 摄像头(Raspberry Pi AI Camera)教程
  • SpringBoot实现的师生健康信息管理平台
  • 启用vnc访问Dell 服务器IDRAC 7虚拟控制台
  • 分布式数据库知识详解
  • 无人化焦炉四大车系统 武汉正向科技 工业机车无人远程控制系统
  • 【Linux】几种常见配置文件介绍
  • 【2024最新】华为HCIE认证考试流程
  • Golang | Leetcode Golang题解之第453题最小操作次数使数组元素相等
  • 想知道为什么有DICOM格式,YAML格式,XML格式,JSON格式吗?
  • Kubernetes环境搭建
  • draw.io创建自定义形状
  • 【CSS3】css开篇基础(1)
  • 华为杯”第十二届中国研究生数学建模竞赛-D题:单/多列车优化决策问题的研究
  • 【Docker】docker的存储
  • C++游戏开发深度解析
  • 计算机毕业设计 基于Python的无人超市管理系统的设计与实现 Python+Django+Vue 前后端分离 附源码 讲解 文档
  • dockercommit 后的镜像没有数据
  • 基于SD卡的基因(DNA)炫酷LED桌面灯
  • 【算法系列-链表】设计链表
  • 螺狮壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习03(网络及IP规划)
  • Zookeeper下载、安装配置
  • 【代码记录】多线程示例代码
  • 【数据结构】什么是平衡二叉搜索树(AVL Tree)?
  • ip的类型有多少种?我想做大数据需要使用哪一种
  • 位运算(6)_只出现一次的数字 II
  • C#的Socket编程细节