oracle很有用的統計函數rank和cume

來源:互聯網
上載者:User

標籤:clerk

oracle 10g 裡面有scott使用者

alter user scott account unlock ;

使用 scott 密碼 tiger 進入,修改密碼,改使用者有emp 表;

rank函數 :

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 ;


DEPTNO JOB SUM(SAL) JOBDEP_RANK SUMSAL_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);


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

 有了這兩個有用的函數,排名和百分比很快就能得到了吧。


oracle很有用的統計函數rank和cume

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.