2011. 11. 15. 10:50

[Oracle] RANK() 함수 Sample

SELECT X.BAYONG, X.YONGNM, X.GADAMT, 
             RANK() OVER(ORDER BY X.GADAMT DESC) RNKAMT
   FROM ( SELECT A.BAYONG, B.YONGNM, SUM(A.CHARGE + A.DLVAMT) GADAMT
                  FROM INVCON A
                    JOIN YNGMST B
                      ON B.YONGCD = A.BAYONG
                WHERE A.JBDATE BETWEEN '2011-11-01' AND '2011-11-02'
                GROUP BY A.BAYONG, B.YONGNM
             ) X
  ORDER BY RNKAMT

>>

BAYONG YONGNM     GADAMT   RNKAMT
--------- ---------- ---------- ----------
TG11        남대구         8909456          1
SEB8        광장            8540758          2
KGB3       파주탄현       8163140          3
JN55        장흥             7447275          4
KG14       공단안산        7071694          5
...

'Database / Sql' 카테고리의 다른 글

[Oracle] 오라클 버전 확인  (0) 2011.11.16
[Oracle] ORA-01476 : 제수가 0  (0) 2011.11.16
[Oracle] RANK() 함수 Sample  (0) 2011.11.15
[Oracle] PL/SQL PROCEDURE Sample  (0) 2011.11.14
[Oracle] PL/SQL FUNCTION Sample  (0) 2011.11.14
[Oracle] SAVEPOINT & TRANSACTION  (0) 2011.09.02
Trackback 0 Comment 0