sql >> Database teknologi >  >> RDS >> Oracle

Transponering og aggregering af Oracle-kolonnedata

Du kan bruge listagg() vinduesanalysefunktion to gange som

with t1( Base, End ) as
( 
 select 'RMSA','Item 1' from dual union all
 select 'RMSA','Item 2' from dual union all 
 select 'RMSA','Item 3' from dual union all
 select 'RMSB','Item 1' from dual union all
 select 'RMSB','Item 2' from dual union all
 select 'RMSC','Item 4' from dual 
),
   t2 as
(   
select 
       listagg(base,';') within group (order by end) 
       as key,
          end   
  from t1
 group by end 
)
select key, 
       listagg(end,',') within group (order by end) 
       as Products
  from t2  
 group by key
 order by products;

Key           Products
---------     --------------
RMSA;RMSB     Item 1, Item 2
RMSA          Item 3
RMSC          Item 4  

Demo



  1. mindste mysql-type, der rummer en enkelt decimal

  2. Få serveren til at køre automatisk asp-script hver dag

  3. Hvordan kan jeg bruge MySQL-database fra to forskellige servere i PHP?

  4. OPENJSON "Forkert syntaks nær søgeordet 'med'." i SQL Server (LØST)