獲取所有員工當前的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 as a join dept_manager as b
on a.dept_no = b.dept_no and not a.emp_no = b.emp_no
where a.to_date = '9999-01-01' and b.to_date = '9999-01-01';