查找所有员工自入职以来的薪水涨幅情况,给出员工编号emp_noy以及其对应的薪水涨幅growth,并按照growth进行升序
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));
建立两张表,分别存放员工当前工资和员工入职工资,然后将两表并列查询。
select a.emp_no,(b.salary-a.salary) as growth from (select e.emp_no,s.salary from salaries s,employees e where s.emp_no=e.emp_no and s.from_date=e.hire_date) as a, (select e.emp_no,s.salary from salaries s,employees e where s.emp_no=e.emp_no and s.to_date='9999-01-01') as b where a.emp_no=b.emp_no order by growth