Oracle over function usage

Source: Internet
Author: User

Oracle over function usage rank () over ([query_partition_clause] order_by_clause) dense_rank () over ([query_partition_clause] order_by_clause) can be grouped by specified fields, sort the result set of the same grouping field. partition by is the grouping field, and order by cannot be used separately because it must be used with the analysis functions rank (), dense_rank (), row_number () and so on. Its Parameter: over (partition by columnname1 order by columnname2) meaning: sort by columname1 by group, or by the value of columnname1 by group. For example, in the employees table, there are two Department records: department_id = 10 and 20 select department_id, rank () over (partition by department_id order by salary) from employees refers to the ranking of salaries in department 10 and in department 20. If it is partition by org_id, It is ranked within the company. For example, grouping the same code but the title is empty, grouping the rate first, and then sorting by row_number () select table1.code, row_number () over (partition by t1.code order by nvl (title, 0) desc) num from table1 where table1.status = 1 order by code: code num ----------------------- -------- 1 420000029 12 420000029 23 420000031 14 420000032 15 420000046 16 420000046 2

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.