Oracle is useful for statistical functions rank and Cume

Source: Internet
Author: User

There are Scott users in Oracle 10g

Alter user Scott account unlock;

Use the Scott password Tiger to enter, change the password, change the user has an EMP table;

Rank function:

SELECT deptno, Job, SUM (SAL),
RANK () over (PARTITION by Deptno ORDER by
SUM (SAL) DESC)
As Jobdep_rank,rank () over (ORDER by SUM (SAL) DESC) as Sumsal_rank
From EMP
GROUP by Deptno, job;


< Span style= "font-family: ' The song Body '; >deptno job sum (SAL) jobdep_rank
20 analyst 6000 1 1
30 salesman 5600 1 2
10 president 5000 1 3
20 manager 2975 2 4
30 manager 2850 2 5
10 manager 2450 2 6
20 clerk 1900 3 7
10 clerk 1300 3 8
30 Clerk 950 3 9


Cume_dist

SELECT deptno, Job, SUM (SAL),
Cume_dist () over (PARTITION by Deptno ORDER by
SUM (SAL) DESC)
As CUME_DIST_PER_DEP
From EMP
GROUP by Deptno, job
ORDER by Deptno, SUM (SAL);


< Span style= "font-family: ' The song Body '; >deptno job sum (SAL) CUME_DIST_PER_DEP
10 clerk 1300 1
10 manager 2450 0.666667
10 president 5000 0.333333
20 clerk 1900 1
20 manager 2975 0.666667
20 analyst 6000 0.333333
30 clerk 950 1
30 manager 2850 0.666667
30 Salesman 5600 0.333333

With these two useful functions, the rankings and percentages will soon be available.


Oracle is useful for statistical functions rank and Cume

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.