题目:查找所有员工入职时候的薪水情况,给出emp_no以及salary,并按照emp_no进行逆序

方法1:子查询
select s.emp_no, s.salary
from salaries as s
where from_date = (select e.hire_date from employees as e where e.emp_no = s.emp_no)
order by s.emp_no desc;

方法2:使用内连接,hire_date时间和from_date时间一致
select e.emp_no, s.salary
from employees as e
inner join salaries as s
on e.emp_no = s.emp_no
where s.from_date = e.hire_date
order by e.emp_no desc;

方法3:使用(逗号)并列查询,hire_date时间和from_date时间一致
select e.emp_no, s.salary
from employees as e, salaries as s
where e.emp_no = s.emp_no
and s.from_date = e.hire_date
order by e.emp_no desc;
注意:内连接是取左右两张表的交集形成一个新表,用From并列两张表后仍然是两张表。如果还要对新表进行操作则要用内连接。从效率上看应该并列查询更快,因为不用形成新表。

方法4:获取salaries表中from_date中最小值对应的emp_no和salary,只用到salaries表
select emp_no, salary
from salaries
group by emp_no
having min(from_date)
order by emp_no desc;