Usage of the OVER function in SQL statements

Source: Internet
Author: User

Over cannot be used alone, with analytic functions: Rank (), Dense_rank (), Row_number (), and so on.
Its parameters: Over (partition by columnname1 ORDER by Columnname2)
Meaning: Group by the field specified by Columname1, or by the value of field columnname1 to sort by group.
For example: In the Employees table, there are two records for the department: department_id = 10 and 20
Select Department_id,rank () over (partition by department_id order by salary) from employees is the ranking of salaries in department 10, Make a salary ranking in department 20. If it is partition by org_id, it is ranked throughout the company.

The following are personal insights:

The over function in SQL and the Row_numbert () function work together to generate line numbers. You can sort the values of a column by grouping the rows of data that have the same value.

Execute statement: Select Row_number () over (order by AID DESC) as rowid,* from BB

Usage of the OVER function in SQL statements

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.