Row column conversion after Oracle 11

Time:2021-3-1

After Oracle 11, there is a new method of row column conversion.

The following is the dredged code, please rest assured to use…

With AA as (

Select A,B,C,row_number() over (partition by B order by b) D from (

  Select 10 A, 11 B, 12 C from dual

  union 

  select 20,11,22 from dual

  union

  select 30 , 21 , 32 from dual )  

)

Select * from AA pivot (Max(A) , Max(C) for B in (11,21))

 

remarks

Field B is supposed to determine the date. If you need a dynamic column, you can alias the max item, so that the dynamic column can be realized.

 

be careful

If the row and column conversion is not performed in the whole field, it is not necessary to add row_ number,

If it is added, some data will not be changed to the column because the row of the same item_ Number may be different.

Recommended Today

Practice analysis of rust built-in trait: partialeq and EQ

Abstract:Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. This article is shared from Huawei cloud community《Analysis of rust built-in trait: partialeq and EQ》Author: debugzhang Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. Some traits can be automatically […]