Score
0
Watch 44 Star 256 Fork 69

xuthus / 数据库SQL实战SQLMIT

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
9.获取所有部门当前manager的当前薪水情况.md 839 Bytes
Copy Edit Web IDE Raw Blame History
xuthus authored 2019-08-13 08:38 . revise:content revision

获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'

题目描述

获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'

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`));

答案

select dm.dept_no,dm.emp_no,s.salary from dept_manager dm left join salaries s on dm.emp_no = s.emp_no where s.to_date = '9999-01-01' and dm.to_date = '9999-01-01'

题解

连接后过滤

Comment ( 0 )

Sign in for post a comment