Find the current salary details of the current leaders of each department and the corresponding department number dept_no [3]

Title description

Find the current (dept_manager.to_date='9999-01-01') leader's current (salaries.to_date='9999-01-01') salary details of each department and its corresponding department number dept_no

(Note: The output result is sorted in ascending order of salaries.emp_no, and please note that the dept_no column in the output result is the last column)

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

TABLE `dept_manager` the CREATE (
` dept_no` char (4) the NOT NULL, - 'department number'
`emp_no` int (11) the NOT NULL, - 'employee number'
` DATE to_date` the NOT NULL,
PRIMARY KEY ( `emp_no `,`dept_no`));

Enter description:

no

Output description:

emp_no salary from_date to_date dept_no
10002 72527 2001-08-02 9999-01-01 d001
10004 74057 2001-11-27 9999-01-01 d004
10005 94692 2001-09-09 9999-01-01 d003
10006 43311 2001-08-02 9999-01-01 d002
10010 94409 2001-11-23 9999-01-01 d006

answer: 

select s.*,d.dept_no 
from salaries as s inner join dept_manager as d
on s.emp_no=d.emp_no
where s.to_date='9999-01-01' and d.to_date='9999-01-01'

 

Guess you like

Origin blog.csdn.net/gjs935219/article/details/109187392