Using analytic functions for row and column conversions

Source: Internet
Author: User

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

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.