Select the nth value from the row in the table.

Source: Internet
Author: User

Select the nth big/small value from the row in the table. The software environment Windows Server 2008 R2Oracle 11g Release 1 (11.1) Oracle SCOTT user uses SCOTT's EMP table in this article. The content is as follows: SQL> select empno, ename, sal 2 from emp 3 order by sal desc; empno ename sal ---------- 7839 KING 5000 7902 FORD 3000 7788 SCOTT 3000 7566 JONES 2975 7698 BLAKE 2850 CLARK 7782 2450 ALLEN 7499 TURNER 1600 7844 MILLER 1500 7934 WARD 1300 7521 MARTIN 1250 EMPNO ename sal ---------- 7876 ADAMS 1100 7900 JAMES 950 7369 SMITH 800 has selected 14 rows. SQL> select the nth value from the table SQL> select level, max (sal) 2 from emp 3 where level = '& n' 4 connect by prior sal> sal 5 group by level; input n value: 1 Original Value 3: where level = '& n' new value 3: where level = '1' level max (SAL) -------------- 1 5000 SQL> select level, max (sal) 2 from emp 3 where level = '& n' 4 connect by prior sal> sal 5 group by level; input n value: 3 Original Value 3: where level = '& n' new value 3: where level = '3' level max (SAL) ---------- 3 2975 SQL> select the nth small value from the table SQL> select level, min (sal) 2 from emp 3 where level = '& n' 4 connect by prior sal <sal 5 group by level; input n value: 1 Original Value 3: where level = '& n' new value 3: where level = '1' level min (SAL) -------------- 1 800 SQL> select level, min (sal) 2 from emp 3 where level = '& n' 4 connect by prior sal <sal 5 group by level; input n value: 5 Original Value 3: where level = '& n' new value 3: where level = '5' level min (SAL) ---------- 5 1300 SQL>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.