当前位置: 移动技术网 > IT编程>数据库>MSSQL > 数据库SQL实战:查找员工编号emp_now为10001其自入职以来的薪水salary涨幅值growth(教程)

数据库SQL实战:查找员工编号emp_now为10001其自入职以来的薪水salary涨幅值growth(教程)

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

制作图片的网站,收获之夜漫画,猛犸毁灭者卡奥

题目描述

查找员工编号emp_now为10001其自入职以来的薪水salary涨幅值growth

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、先分别找到emp_no=10001的员工的第一次工资记录与最后一次工资记录

2、再将最后一次工资记录减去第一次工资记录得到入职以来salary的涨幅,最后用别名growth代替

select 
(select salary from salaries where emp_no='10001' order by to_date desc limit 1)-
(select salary from salaries where emp_no='10001' order by to_date limit 1)
as growth

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

相关文章:

验证码:
移动技术网