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

查找员工编号emp_no为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));

–select 也可以这么用:将to_date 最大值(当前)的薪水-to_date 最小值(入职当天)的薪水拿到

select
((select salary 
from salaries 
where emp_no = 10001 
order by to_date desc
limit 0,1)
-
(select salary 
from salaries 
where emp_no = 10001 
order by to_date asc
limit 0,1))
as growth;
发布了292 篇原创文章 · 获赞 73 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43777983/article/details/104485858