Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Mon, 12 Jan 2004 @ 21:04:35 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: How to concatenate the column values
 
From:   Babu, Mahesh

If you know the C2 values before hand, you can achieve this one by using a straight SQL like this.

SELECT
C1,
max(case when c2 = value1 then c2 else '' end)||
max(case when c2 = value2 then c2 else '' end)||
max(case when c2 = value3 then c2 else '' end)||
max(case when c2 = value4 then c2 else '' end)
from table
group by 1;

If you don't know the values, then using CSUM and a derived table will do the trick.

SELECT
C1,
max(case when rnk = 1 then c2 else '' end)||
max(case when rnk = 2 then c2 else '' end)||
max(case when rnk = 3 then c2 else '' end)||
max(case when rnk = 4 then c2 else '' end)||
-
-
-
from
        (select c1,c2,csum(1,c2) rnk from table
        group by 1) derived
group by 1;

Thanks

Mahesh



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023