问题: 查找薪金水平处于第四位的雇员  表名 employees  列 last_name和salary
      
 select last_name,salary
  from (select rownum rm,
     (select salary,last_name
     from employees
     order by salary desc)
     from employees) haha
  where haha.rm = 4我是这样写的 提示错误 order by 位置 缺失右括号  用ORACLE 数据库
各位大哥帮帮忙~~谢谢

解决方案 »

  1.   

    select salary,last_name from(
       select salary,last_name,row_number()over(order by salary desc) rn
       from employees
    )
    where rn=4;
      
      

  2.   

    select last_name,salary
    from 
    (select last_name,salary,row_number()over(order by salary desc) rownum
     from employees)
    where rownum=4;--or
    子查询 不写了
      

  3.   

    补充~~~现在还没学过 row_number()over......
    只会rownum这东西~……
      

  4.   


    select last_name,salary
    from 
      (select salary,last_name,row_number() over(order by salary desc) rn
      from employees) 
    where rn = 4
      

  5.   


    select last_name,salary
    from 
      (select salary,last_name,rownum rn
      from employees order by salary desc) 
    where rn = 4
      

  6.   

    5L的大哥 我这是作业~……要是用没学过的东西达不到练习今天讲课的内容啊~ 还有 你写的这个不对~出不来想要的结果 rm 的顺序跟order的顺序会冲突的~也就是说salary排在第一的人 rm的值不是1
      

  7.   


    select last_name,salary from(
       select select salary,last_name,rownum rn from(
           select salary,last_name from employees order by salary desc) 
    )
    where rn = 4
      

  8.   


    select last_name,salary from(
       select salary,last_name,rownum rn from(
           select salary,last_name from employees order by salary desc) 
    )
    where rn = 4
      

  9.   


    其结果如下
     SALARY LAST_NAME
    ------- ------------
      14000 Russell
      

  10.   

    select a.last_name, a.salary
      from (select last_name,
                   salary,
                   rank() over(partition by last_name order by salary desc) rank
              from employee) a
     where a.rank = 4
      

  11.   

     select last_name,salary
      from (select rownum rm,a.salary,a.last_name
    from
      (select salary,last_name
      from employees a
      order by salary desc)
      ) h