题目描述:查找所有员工入职时候的薪水情况,
给出emp_no以及salary, 并按照emp_no进行逆序(请注意,一个员工可能有多次涨薪的情况)
CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_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`));
(1)方法1
select e.emp_no,s.salary from employees e
left join salaries s
on e.emp_no=s.emp_no and e.hire_date=s.from_date
order by e.emp_no desc
(2)方法2
select a.emp_no,b.salary
from employees as a
left join salaries as b
on a.emp_no=b.emp_no
where a.hire_date=b.from_date and salary is not null
order by a.emp_no desc
;
(3)方法3
SELECT e.emp_no, s.salary
FROM employees AS e
INNER JOIN salaries AS s
ON e.emp_no = s.emp_no AND e.hire_date = s.from_date
ORDER BY e.emp_no DESC
�����ʷ9�{��
暂无数据