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

题目描述

查找员工编号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
(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐