Over in Oracle (partition by ...) Analytic functions and window-opening functions

Source: Internet
Author: User

Suppose there is a table student

Name Score Inserttime (name: Name score: Score inserttime: Test time)

Zhang 320 2015-08-08

Lee 412 2015-09-01

Little Q 33 2015-09-03

Zhang 320 2015-09-08

Lee 412 2015-07-01

Little Q 25 2015-06-03

Now ask everyone to sort by the order of the test time, write out the Oracle statement

For:

Select Row_number () over (partition by name order by Inserttime) row_number,student.* from student

Explain:

Partition by first grouping by name, order by in order by Inserttiom

Results

Zhang 320 2015-08-08

Zhang 320 2015-09-08

Lee 412 2015-07-01

Lee 412 2015-09-01

Little Q 25 2015-06-03

Little Q 33 2015-09-03

This method can be applied flexibly. For example, take the latest data from each group or the first data

Select Row_number () over (partition by name order by Inserttime) row_number,student.* from student where row_number=1

Zhang 320 2015-08-08

Lee 412 2015-07-01

Little Q 25 2015-06-03

Have questions direct message first time reply

Over in Oracle (partition by ...) Analytic functions and window-opening functions

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.