Row to column unpivot, column shift pivot, note that Oracle 11g and later support

Source: Internet
Author: User
The existing table, the original data is as follows: Now you need to query the following results (conditions are: [80,~] Excellent, [60,80) pass, [~,60] failed):
The original table is converted with UNPIVOT, and the line changes to select * from CB_SHANGCICB UNPIVOT ("language", "math", "English"), and the results are as follows: The CJ is then matched with the band TT as (select * FROM Score Unpivot (CJ-KC in ("Language", "math", "English"))) Select KC, (case is cj>=80 then ' excellent ' when cj>=60 then ' Pass ' El Se ' failed ' end ' CJ from TT; execution results are as follows: Then use pivot for the column change select * FROM (with TT as (SELECT * from Score Unpivot (CJ for KC in ("Language", " Math "," English "))) Select KC, (case when cj>=80 then ' excellent ' when cj>=60 then ' pass ' else ' fail ' end) CJ from TT) PIVOT Max (CJ) for the KC in (' Language ' as ' language ', ' math ' as ' math ', ' English ' as ' English '), the red background part must be an aggregate function;

Row to column unpivot, column shift pivot, note that Oracle 11g and later support

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.