首页

oracle没有top-n函数如何实现查询最大或最小前多少记录sql查询

标签:top n     发布时间:2021-12-29   

1. Finds the two highest salaries from table "emp".

select a.empno,a.sal @b@from emp a@b@where 2>@b@(@b@select count(*) @b@from emp @b@where sal>a.sal@b@);

2. Finds the two lowest salaries from table "emp".

select a.empno,a.sal @b@from emp a@b@where 2>@b@(@b@select @b@count(*)@b@from emp@b@where sal<a.sal@b@)

另外

select [column_list],ROWNUM@b@   from (@b@        select [column_list]@b@        from table_name ORDER BY top-n_column  ) @b@   where ROWNUM <= N;











  • ◆ 相关内容