1. 题目:
查找员工编号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 (
(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 asc
limit 1)
) as growth;
- 在select后做运算得到想要的值
如 select 100%98; - 按照时间逆排序得到最新的工资值
- 按照时间正排序得到最远的工资值
- to_date是列名,不要加引号,不是当做字符用