zoukankan      html  css  js  c++  java
  • SQL-21 查找所有员工自入职以来的薪水涨幅情况,给出员工编号emp_no以及其对应的薪水涨幅growth,并按照growth进行升序

    题目描述

    查找所有员工自入职以来的薪水涨幅情况,给出员工编号emp_no以及其对应的薪水涨幅growth,并按照growth进行升序
    CREATE TABLE `employees` (
    `emp_no` int(11) NOT NULL,
    `birth_date` date NOT NULL,
    `first_name` varchar(14) NOT NULL,
    `last_name` varchar(16) NOT NULL,
    `gender` char(1) NOT NULL,
    `hire_date` date NOT NULL,
    PRIMARY KEY (`emp_no`));
    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`));

    输入描述:

    输出描述:

    emp_nogrowth
    10011 0
    省略 省略
    10010 54496
    10004 34003

    SQL:

    select sCurrent.emp_no,(sCurrent.salary-sStart.salary)as growth
    from(select emp_no,salary from salaries where to_date='9999-01-01')as sCurrent,
        (select e.emp_no,c.salary from employees e,salaries c where e.emp_no=c.emp_no and c.from_date=e.hire_date)as sStart
    where sCurrent.emp_no=sStart.emp_no
    order by growth
    

       分别找出 当前的工资 以及入职时工资 将这两张表进行连接 然后计算出growth 

  • 相关阅读:
    烦人的警告 Deprecated: convertStrings was not specified when starting the JVM
    Python 推送RabbitMQ
    JavaScript-json数组排序
    CSS-返回顶部代码
    CSS-页面滑屏滚动原理
    CSS-图像映射
    CSS-下拉导航条
    CSS-background-position百分比
    CSS- 横向和纵向时间轴
    JavaScript-闭包深入浅出
  • 原文地址:https://www.cnblogs.com/kexiblog/p/10683481.html
Copyright © 2011-2022 走看看