SQL3-查找各个部门当前(to_date='9999-01-01')领导当前薪水详情以及其对应部门编号dept_no

题目描述

查找各个部门当前(to_date='9999-01-01')领导当前薪水详情以及其对应部门编号dept_no
CREATE TABLE `dept_manager` (
`dept_no` char(4) NOT NULL,
`emp_no` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`dept_no`));
CREATE TABLE `salaries` (
`emp_no` int(11) NOT NULL,
`salary` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`from_date`));
思路:这个依据emp_no连接 两个表的交集    但是
需要对两个表的时间都作限定是因为:
1、薪水是按年分发的,薪水会变动  所以要对 salaries进行限定
2、部门会离职  需要对dept_manger进行限定
SQL:
select s.*,d.dept_no from salaries s join dept_manager d
    on s.emp_no=d.emp_no
    where s.to_date='9999-01-01'and d.to_date='9999-01-01'

  

 
 
原文地址:https://www.cnblogs.com/kexiblog/p/10647183.html