How to Use partitionby in Oracle, oraclepartitionby

Source: Internet
Author: User

How to Use partitionby in Oracle, oraclepartitionby

The Parttion by keyword is an analytics function in Oracle, which can be grouped and sorted,

Used together with the row_number (), rank (), dense_rank () Functions

-- Row_number () ordered sorting

Select row_number () over (partition by class order by score desc) ranking, NO, score, class from A_TEST

-- Rank () skip sorting. If there are two first-level instances, the next step is the third-level instances.

Select rank () over (partition by class order by score desc) ranking, NO, score, class from A_TEST

-- Dense_rank (): consecutive sorting. If there are two first-level instances

Select dense_rank () over (partition by class order by score desc) ranking, NO, score, class from A_TEST

A_TEST

NO CLASS SCORE

1001 1 99

1002 2 98

1001 3 97

1004 1 98

1005 1 97

1006 1 99

1007 2 98

1008 3 97

Execution result

① Select row_number () over (partition by class order by score desc) ranking, NO, score, class from A_TEST;

NO SCORE CLASS

1 1001 99 1

2 1006 99 1

3 1004 98 1

4 1005 97 1

1 1002 98 2

2 1007 98 2

1 1008 97 3

2 1001 97 3

② Select rank () over (partition by class order by score desc) ranking, NO, score, class from A_TEST;

NO SCORE CLASS

1 1001 99 1

1 1006 99 1

3 1004 98 1

4 1005 97 1

1 1002 98 2

1 1007 98 2

1 1008 97 3

1 1001 97 3

③ Select dense_rank () over (partition by class order by score desc) ranking, NO, score, class from A_TEST;

NO SCORE CLASS

1 1001 99 1

1 1006 99 1

2 1004 98 1

3 1005 97 1

1 1002 98 2

1 1007 98 2

1 1008 97 3

1 1001 97 3

By ranking, you can know the differences between the three functions.

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.