当前位置:网站首页>Database SQL practice 3. Find the current salary details of the current leaders of each department and their corresponding department number Dept_ no
Database SQL practice 3. Find the current salary details of the current leaders of each department and their corresponding department number Dept_ no
2022-07-05 07:12:00 【Just as young】
Title Description
Find the current (dept_manager.to_date=‘9999-01-01’) Lead the current (salaries.to_date=‘9999-01-01’) Salary details and their corresponding department numbers dept_no
( notes : Please use salaries Table is used to query the main table , Output the result with salaries.emp_no Ascending sort , And please note in the output dept_no Column is the last column )
CREATE TABLE `salaries` (
`emp_no` int(11) NOT NULL, -- ' Employee number ',
`salary` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`from_date`));
CREATE TABLE `dept_manager` (
`dept_no` char(4) NOT NULL, -- ' Department number '
`emp_no` int(11) NOT NULL, -- ' Employee number '
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`dept_no`));
Input description :
nothing
Output description :
emp_no | salary | from_date | to_date | dept_no |
---|---|---|---|---|
10002 | 72527 | 2001-08-02 | 9999-01-01 | d001 |
10004 | 74057 | 2001-11-27 | 9999-01-01 | d004 |
10005 | 94692 | 2001-09-09 | 9999-01-01 | d003 |
Their thinking
Due to the requirements of the topic salaries Table is used to query the main table , Output the result with salaries.emp_no Ascending sort , And please note in the output dept_no Column is the last column .
We use left join Left connecting handle salaries Table as the main table , And then use order by Yes salaries.emp_no Sort in ascending order , And dept_no List as select The last column of .
Implementation code
select s.*, d.dept_no
from salaries as s
left join dept_manager as d
on s.emp_no = d.emp_no
where d.to_date = '9999-01-01' and s.to_date = '9999-01-01'
order by s.emp_no
边栏推荐
猜你喜欢
目标检测系列——Faster R-CNN原理详解
C语言数组专题训练
SOC_ SD_ DATA_ FSM
Volcano 资源预留特性
[vscode] prohibit the pylance plug-in from automatically adding import
Use the Paping tool to detect TCP port connectivity
Brief description of inux camera (Mipi interface)
PHY drive commissioning - phy controller drive (II)
【无标题】
程序中的负数存储及类型转换
随机推荐
【软件测试】05 -- 软件测试的原则
第 2 章:小试牛刀,实现一个简单的Bean容器
乐鑫面试流程
PHY驱动调试之 --- PHY控制器驱动(二)
Concurrent programming - deadlock troubleshooting and handling
U-boot initialization and workflow analysis
逻辑结构与物理结构
IPage能正常显示数据,但是total一直等于0
[solved] there is something wrong with the image
Spinningup drawing curve
PHY drive commissioning - phy controller drive (II)
2022年中纪实 -- 一个普通人的经历
Technology blog learning website
[vscode] recommended plug-ins
[software testing] 02 -- software defect management
Ros2 - workspace (V)
Xavier CPU & GPU high load power consumption test
Preemption of CFS scheduling
【软件测试】02 -- 软件缺陷管理
ModuleNotFoundError: No module named ‘picamera‘