In fact, it's a good way to work with analytic functions, flipping through Tom's book and including one of the examples here. For example, to query the Scott.emp table for user Sal ordering information, you can use the following query: SQL> SELECTDeptno, ename,2Row_number () Over(PARTITION byDeptnoORDER bySalDESC) Seq3 fromEMP; DEPTNO ename SEQ---------- ---------- ---------- TenKING1 TenCLARK2 TenMILLER3 -SCOTT1 -FORD2 -JONES3 -Adams4 -SMITH5 -BLAKE1 -ALLEN2 -TURNER3 -WARD4 -MARTIN5 -JAMES6 -rows selected. Then combine the other functions for a row and column conversion: SQL> SelectDeptno,2 Max(Decode (SEQ,1, ename,NULL)) Highest,3 Max(Decode (SEQ,2, ename,NULL)) Second,4 Max(Decode (SEQ,3, ename,NULL)) Third5 from ( 6 SelectDeptno,ename,7Row_number () Over 8(Partition byDeptnoOrder bySaldesc) Seq9 fromEMP)Ten whereSeq<=3 Group byDeptno One /DEPTNO highest SECOND third---------- ---------- ---------- ---------- TenKING CLARK MILLER -SCOTT FORD JONES -BLAKE ALLEN TURNER
Using analytic functions for row and column conversions