当前位置:网站首页>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
边栏推荐
- Ros2 - first acquaintance with ros2 (I)
- ROS2——初识ROS2(一)
- Mid 2022 documentary -- the experience of an ordinary person
- Matlab在线性代数中的应用(四):相似矩阵及二次型
- ROS2——ROS2对比ROS1(二)
- docker安装mysql并使用navicat连接
- PostMessage communication
- Orin installs CUDA environment
- 解读最早的草图-图像翻译工作SketchyGAN
- Mipi interface, DVP interface and CSI interface of camera
猜你喜欢
随机推荐
[software testing] 03 -- overview of software testing
SD_CMD_SEND_SHIFT_REGISTER
[vscode] recommended plug-ins
Marvell 88e1515 PHY loopback mode test
【无标题】
An article was opened to test the real situation of outsourcing companies
Instruction execution time
U-Boot初始化及工作流程分析
1290_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
The difference between NPM install -g/-save/-save-dev
【软件测试】03 -- 软件测试概述
Error: "mountvolume.setup failed for volume PVC fault handling
[solved] there is something wrong with the image
SOC_ SD_ DATA_ FSM
Use the Paping tool to detect TCP port connectivity
Logical structure and physical structure
现在有html文件,和用vs制作的mvc(连接了数据库),怎么两个相连?
程序中的负数存储及类型转换
【obs】x264编码:“buffer_size“
第 2 章:小试牛刀,实现一个简单的Bean容器