1. Get the current manager of all employees. If the current manager is one's own, the result will not be displayed, and the current means to_date='9999-01-01'.
As a result, the first column gives the emp_no of the current employee, and the second column gives the manager_no corresponding to its manager.
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
));
Note: When answering, although the position is different, the department number is the same.
select d.emp_no, m.emp_no as manager_no
from dept_emp d, dept_manager m
where d.to_date='9999-01-01'
and m.to_date='9999-01-01'
and d.dept_no =m.dept_no
and d.emp_no !=m.emp_no
2. Get the relevant information about the highest salary of the current employee in all departments, and give dept_no, emp_no and their corresponding salary. The
default current is 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 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 dept_no, d.emp_no, max(salary)
from dept_emp d, salaries s
where d.emp_no=s.emp_no
and d.to_date='9999-01-01'and s.to_date='9999-01-01'
group by dept_no