SQL7

作者: xmgh1024 | 来源:发表于2020-02-07 19:52 被阅读0次

题目描述

查找员工编号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 from_date desc limit 1 )-(select  salary  from salaries where emp_no=10001 

    order by from_date asc  limit 1 ) ) as growth

相关文章

  • SQL7

    题目描述 查找员工编号emp_no为10001其自入职以来的薪水salary涨幅值growth CREATE TA...

网友评论

      本文标题:SQL7

      本文链接:https://www.haomeiwen.com/subject/peevxhtx.html