当前位置:网站首页>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
边栏推荐
- postmessage通信
- [vscode] recommended plug-ins
- Technology blog learning website
- [tf] Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initial
- 【Node】nvm 版本管理工具
- Unity ugui how to match and transform coordinates between different UI panels or uis
- [vscode] prohibit the pylance plug-in from automatically adding import
- Energy conservation and creating energy gap
- Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
- 1290_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
猜你喜欢

Ret2xx---- common CTF template proposition in PWN

Marvell 88e1515 PHY loopback mode test

PHY驱动调试之 --- PHY控制器驱动(二)

Ros2 - Service Service (IX)

Negative number storage and type conversion in programs

.net core踩坑实践

SD_CMD_SEND_SHIFT_REGISTER

Volcano 资源预留特性

Orin installs CUDA environment

An article was opened to test the real situation of outsourcing companies
随机推荐
C语言数组专题训练
Orin 两种刷机方式
使用paping工具进行tcp端口连通性检测
逻辑结构与物理结构
ROS2——topic话题(八)
【Node】nvm 版本管理工具
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
Ros2 - Service Service (IX)
ROS2——常用命令行(四)
【MySQL8.0不支持表名大写-对应方案】
1290_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
M2DGR 多源多场景 地面机器人SLAM数据集
程序中的负数存储及类型转换
new和malloc的区别
[tf] Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initial
Concurrent programming - how to interrupt / stop a running thread?
Orin 安装CUDA环境
Binary search (half search)
[node] NVM version management tool
基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现