当前位置: 移动技术网 > IT编程>数据库>MSSQL > 数据库SQL实战:查找所有员工自入职以来的薪水涨幅情况(教程)

数据库SQL实战:查找所有员工自入职以来的薪水涨幅情况(教程)

2018年09月14日  | 移动技术网IT编程  | 我要评论

讲故事大全,钱琳储,上古神器4攻略

查找所有员工自入职以来的薪水涨幅情况,给出员工编号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 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网