Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 26 Mar 2004 @ 17:24:21 GMT


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


Subj:   Re: Crosstab SQL
 
From:   Burton, Bruce

like this?

sel product_code,
sum(case when bill_month between '2003-11-01' and '2003-11-30' then bill_amt
else 0 end) as nov_bill_amt,
sum(case when bill_month between '2003-12-01' and '2003-12-31' then bill_amt
else 0 end) as dec_bill_amt
group by product_code

raw data

product_code    bill_month  bill_amt
prod1           2003-12-15     $5
prod1           2003-11-15     $5
prod2           2003-12-15     $10
prod2           2003-11-15     $10

"pivot" data

product_code   nov_bill_amt   dec_bill_amt

prod1             5                5
prod2            10               10


     
  <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