美文网首页
18.查找当前薪水(to_date='9999-01-01')排

18.查找当前薪水(to_date='9999-01-01')排

作者: Bre_eze | 来源:发表于2018-07-05 16:07 被阅读0次

    查找当前薪水(to_date='9999-01-01')排名第二多的员工编号emp_no、薪水salary、last_name以及first_name,不准使用order by

    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`));
    

    解析:SB题目,为什么不让用order by

    select e.emp_no, max(s.salary), e.last_name, e.first_name
    from employees as e, salaries as s
    where s.to_date = '9999-01-01'
    and e.emp_no = s.emp_no
    and s.salary not in (
        select max(salary)
        from salaries
        where to_date = '9999-01-01'
    )
    

    相关文章

      网友评论

          本文标题:18.查找当前薪水(to_date='9999-01-01')排

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