Oracle Advanced Query-subquery (pagination display case) ____oracle

Source: Internet
Author: User

Case: Paging Query displays employee information: Show employee number, name, salary

1. Display four records per page

2. Employees showing the second page

3. Sort by descending monthly salary

Analysis:

1. You can display the location of the query information by pseudo-column rownum.

Note: RowNum can only use <, <=, can not use >, >=. Line number (rownum) in Oracle will always start at 1

2. Check out employee information in descending order

Select Rownum,empno,ename,sal from emp order by Sal Desc;

3. The results of the above query as a collection, query out the previous 8 records

Select RowNum, Empno,ename,sal from (

Select Rownum,empno,ename,sal from emp desc to Sal E1

where RowNum <8;

4. The first 8 records that have been queried are used as a collection, and the rownum in this collection is not a line number, which can be used as the result of the query

The first column is displayed in the final query results.                   Query 5th, 6, 7, 8 records that is the second page of employee information. Select R,empno,ename,sal
From (select RowNum R, empno,ename,sal
From (select Rownum,empno,ename,sal from emp order BY sal Desc) E1
where RowNum <=8) E2

where r>4;

As shown in the figure:


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.