Get the App
SLTechnology News&Howtos  ›  Database  › 

How to convert pivot to unpivot in Oracle

Shulou Source: shulou.com Published: 2022-05-31 13:12:38 10月03日 Update

It is believed that many inexperienced people do not know what to do about the conversion between pivot and unpivot in Oracle. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

A summary of today's answers to questions

Table:score (student number, Chinese, math, English, chemistry)

Student number Chinese mathematics English chemistry 1 pass excellent excellent fail 2 excellent pass excellent

One of the implementation methods:

Select * from (

With tt as (select * from score unpivot (cj for kc in ("Chinese", "Mathematics", "English", "Chemistry"))

Select "student number", kc

(case when cj > = 80 then 'excellent' when cj > = 60 then 'pass' else 'fail' end) cj

-- decode (sign (cj-80), 0dje 'excellent', 1dje 'excellent',-1dje decode (sign (cj-60), 0pr 'pass', 1pr 'pass', 1dre 'pass', 'fail') cj

From tt)

Pivot (max (cj) for kc in ('Chinese', 'Mathematics', 'English', 'Chemistry'))

After reading the above, have you mastered how to convert pivot to unpivot in Oracle? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Excellence chemistry mathematics Chinese English student numbers methods problems between content more helpless for this reason skills articles experience industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info Microsoft Apple Huawei