题目:获取所有员工当前的manager,如果当前的manager是自己的话结果不显示,当前表示to_date=’9999-01-01’。
结果第一列给出当前员工的emp_no,第二列给出其manager对应的manager_no。
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
));
输入描述:
无
输出描述:
解析:注意他们虽然职位不一样,但是部门是一样的。
select a.emp_no,b.emp_no as manager_no
from dept_emp a,dept_manager b
where a.to_date='9999-01-01' and b.to_date='9999-01-01' and a.dept_no=b.dept_no and a.emp_no !=b.emp_no