24. 獲取所有非manager員工當前的薪水情況
題目描述
獲取所有非manager員工當前的薪水情況,給出dept_no、emp_no以及salary ,當前表示to_date='9999-01-01'
CREATE TABLE `dept_emp` (
`emp_no` int(11) NOT NULL,
`dept_no` char(4) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`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 `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_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`));
輸入描述:
無
輸出描述:
dept_no |
emp_no |
salary |
---|---|---|
d001 |
10001 |
88958 |
d004 |
10003 |
43311 |
d005 |
10007 |
88070 |
d006 |
10009 |
95409 |
SELECT d.dept_no, d.emp_no, s.salary FROM dept_emp d INNER JOIN salaries s ON d.emp_no = s.emp_no WHERE s.to_date = '9999-01-01' AND d.emp_no NOT IN ( SELECT emp_no FROM dept_manager );