如何使用rownum从表中选择第n行

时间:2018-12-18 08:40:26

标签: sql oracle plsql greatest-n-per-group

<mat-sidenav-container class="example-container" fullscreen autosize>
 <app-toolbar></app-toolbar>
  <mat-sidenav #sidenav class="example-sidenav" mode="side" position="end" opened="true">
    <app-main-menu></app-main-menu>
  </mat-sidenav>
</mat-sidenav-container>

我正在尝试获取最大的emp_id。带薪员工 错误消息:ORA-00905:缺少关键字

4 个答案:

答案 0 :(得分:5)

使用FETCH FIRST代替,如果有两个(或多个)具有相同的最高薪水,则添加WITH TIES来获得两者:

SELECT emp_id
FROM cursor_table
ORDER BY emp_salary DESC
FETCH FIRST 1 ROW WITH TIES

答案 1 :(得分:1)

您需要正确的SQL语法

 insert INTO  high_payed_emp_id (emp_id)
 select * from
 (
 SELECT emp_id
 FROM cursor_table ORDER BY emp_salary DESC
  )
 WHERE ROWNUM <= 1;

答案 2 :(得分:1)

SELECT emp_id INTO high_payed_emp_id
FROM (SELECT emp_id  from cursor_table 
WHERE emp_salary = (select max(emp_salary) from cursor_table))a

答案 3 :(得分:0)

在我看来,这是选择Oracle中薪水最高的员工的最简单方法:

select emp_id from cursor_table where emp_salary 
= (select max(emp_salary) from cursor_table)