A small problem encountered in oracle paging Query

Source: Internet
Author: User

A small problem encountered in oracle paging Query

Order table, which has the same order id as the order information table (Multiple order information columns)

Find all orders and their information, and page them by order

select * from(select a. * , (DENSE_RANK() OVER(ORDER BY id DESC)) AS numindex from(SELECT o. * , DENSE_RANK() OVER(ORDER BY o.id DESC) AS rn from order o) a where rn <= 10) where numindex > 0

Find all orders and their information, and page them by order information
SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM order o  left join orderdetail od on o.id=od.orderid ) A WHERE ROWNUM <= 10 ) WHERE RN >= 0

Rank () over, dense_rank (), row_number ()

Rank () over is used to locate a specified condition and perform a ranking, but it has a feature. If it is a ranking of students, then this function is used. The two with the same scores are tied, for example, 1 2 2 4.
















The role of dense_rank () is very similar to rank (). The only difference is that after the rankers' scores are tied together, the next student does not leave a parallel ranking, for example, 1 2 2 3.



Row_number () is different. The difference between row_number () and the preceding two types is obvious. This function does not need to be considered in parallel, continuous ranking is performed even if the value obtained by the condition is the same, as shown in figure

Detailed usage of rank () over, dense_rank (), row_number () http://www.cnblogs.com/wuyisky/archive/2010/02/24/oracle_rank.html


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.