Oracle partition by and partition by... order by grouping

Source: Internet
Author: User

Oracle partition by and partition... order by grouping partition by and partition... difference in order by usage. I just used it. Confused: Table t a B C 1 43 2013-4-17 2 33 2013-4-18 3 10 2013-4-17 use partition by: When rank () is used, use order by Select rank () over (partition by C order by B desc) as rank, C, B, A from t. The result is as follows: rank c B A 1 2013-4-17 43 1 2 2013-4-17 10 3 1 2013-4-18 33 2 hierarchical display of it, for the same date, the sorting method based on order by is upgraded to a certain level. If I want to query the maximum value of Column B in each day, then: select * from (Select rank () over (partition by C order by B desc) as rank, C, B, A from t) table where table. rank = 1. In this way, the highest record rank c B A 1 2013-4-17 43 1 1 2013-4-18 33 2 is used now sum () or count () these functions are used for example: to query the sum of Column B of each day, select sum (B) over (partition by C order by c asc) as sum, C, B, A from t if order by is added here, the data above this time is accumulated, then sum c B a 1 2013-4-17 43 1 53 2013-4-17 10 3 33 2013-4-18 33 2 if order by is not added, that is: select sum (B) over (partition by C) as sum, C, B from t will not accumulate the previous data, as long as the last data is displayed, but multiple; sum c B a 53 2013-4-17 43 1 53 2013-4-17 10 3 33 2013-4-18 33 2 this way, if you calculate the sum of every day, that is, select sum, C from (select sum (B) over (partition by C) as sum, C, B from t) tt group by sum, B, C, then sum C 53 33

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.