当前位置:网站首页>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
边栏推荐
- Lexin interview process
- 目标检测系列——Faster R-CNN原理详解
- ROS2——初识ROS2(一)
- PHY drive commissioning --- mdio/mdc interface Clause 22 and 45 (I)
- The difference between NPM install -g/-save/-save-dev
- M2dgr slam data set of multi-source and multi scene ground robot
- 使用paping工具进行tcp端口连通性检测
- npm install -g/--save/--save-dev的区别
- 三体目标管理笔记
- 2022年中纪实 -- 一个普通人的经历
猜你喜欢
Build a microservice cluster environment locally and learn to deploy automatically
Ethtool principle introduction and troubleshooting ideas for network card packet loss (with ethtool source code download)
Logical structure and physical structure
Spinningup drawing curve
[vscode] prohibit the pylance plug-in from automatically adding import
Brief description of inux camera (Mipi interface)
网易To B,柔外刚中
Log4qt usage of logbase in QT project
Orin two brushing methods
程序中的负数存储及类型转换
随机推荐
mysql设置触发器问题
1290_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
Marvell 88E1515 PHY loopback模式测试
[OBS] x264 Code: "buffer_size“
并发编程 — 如何中断/停止一个运行中的线程?
一文揭开,测试外包公司的真实情况
Ros2 - ros2 vs. ros1 (II)
The differences and connections among cookies, sessions, JWT, and tokens
Error: "mountvolume.setup failed for volume PVC fault handling
Use the Paping tool to detect TCP port connectivity
Build a microservice cluster environment locally and learn to deploy automatically
Ros2 - install ros2 (III)
Logical structure and physical structure
Powermanagerservice (I) - initialization
现在有html文件,和用vs制作的mvc(连接了数据库),怎么两个相连?
npm install -g/--save/--save-dev的区别
U-boot initialization and workflow analysis
Inftnews | drink tea and send virtual stocks? Analysis of Naixue's tea "coin issuance"
[untitled]
Skywalking all