获取员工其当前的薪水比其manager当前薪水还高的相关信息,当前表示to_date=’9999-01-01’,
结果第一列给出员工的emp_no,
第二列给出其manager的manager_no,
第三列给出该员工当前的薪水emp_salary,
第四列给该员工对应的manager当前的薪水manager_salary
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 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
));
这类直接暴力使用where,注意题目的条件。
select e.emp_no as emp_no,m.emp_no as manager_no,s1.salary as emp_salary,s2.salary as manager_salary
from salaries s1,salaries s2,dept_emp e,dept_manager m
where e.emp_no=s1.emp_no
and m.emp_no=s2.emp_no
and e.dept_no=m.dept_no
and e.emp_no!=m.emp_no
and s1.salary>s2.salary
and e.to_date='9999-01-01'
and m.to_date='9999-01-01'
and s1.to_date='9999-01-01'
and s2.to_date='9999-01-01'