当前位置:网站首页>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
边栏推荐
- Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
- Ros2 - common command line (IV)
- GPIO port bit based on Cortex-M3 and M4 with operation macro definition (can be used for bus input and output, STM32, aducm4050, etc.)
- Do you choose pandas or SQL for the top 1 of data analysis in your mind?
- Build a microservice cluster environment locally and learn to deploy automatically
- [framework] multi learner
- window navicat连接阿里云服务器mysql步骤及常见问题
- 扫盲-以太网MII接口类型大全-MII、RMII、SMII、GMII、RGMII、SGMII、XGMII、XAUI、RXAUI
- 【软件测试】05 -- 软件测试的原则
- SD_CMD_SEND_SHIFT_REGISTER
猜你喜欢
ROS2——功能包(六)
C learning notes
Solve tensorfow GPU modulenotfounderror: no module named 'tensorflow_ core. estimator‘
PowerManagerService(一)— 初始化
Ros2 - install ros2 (III)
C#学习笔记
. Net core stepping on the pit practice
【软件测试】02 -- 软件缺陷管理
[software testing] 04 -- software testing and software development
Orin 安装CUDA环境
随机推荐
【obs】x264编码:“buffer_size“
ROS2——ROS2对比ROS1(二)
2022.06.27_每日一题
Marvell 88E1515 PHY loopback模式测试
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
ModuleNotFoundError: No module named ‘picamera‘
PowerManagerService(一)— 初始化
2022年中纪实 -- 一个普通人的经历
GPIO port bit based on Cortex-M3 and M4 with operation macro definition (can be used for bus input and output, STM32, aducm4050, etc.)
SOC_SD_CMD_FSM
[untitled]
Application of MATLAB in Linear Algebra (4): similar matrix and quadratic form
The difference between new and malloc
SD_ CMD_ RECEIVE_ SHIFT_ REGISTER
Unity UGUI不同的UI面板或者UI之间如何进行坐标匹配和变换
第 2 章:小试牛刀,实现一个简单的Bean容器
【软件测试】03 -- 软件测试概述
【Node】npm、yarn、pnpm 区别
Three body goal management notes
Qt项目中的日志库log4qt使用