Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 16 Feb 2005 @ 23:25:19 GMT


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


Subj:   Re: Changing oracle code to teradata
 
From:   Anomy Anom

<-- Anonymously Posted: Wednesday, February 16, 2005 18:23 -->

Not that it is any simpler or faster, but if you wanted to do this in plain SQL....

     /****************************************************************
      *     1. Determine latest weekday in a derived table (x).
      *     2. & 3. Determine the count for all days with the same
      *           weekday in a derived table (y).
      *     4. Calculate mean, latest count, and variance using case.
      ****************************************************************/

     select last_date
     , avg(case when Bus_date < last_date then cnt end) as mean
     , sum(case when Bus_date = last_date then cnt end) as rec
     , (rec - mean)*100/mean as result
     from (
          select Bus_date, last_date, count(*) cnt
          from payments
          , (select max(Bus_date) last_date from payments)x
          where Bus_date > (last_date - 240)
               and Bus_date <= last_date
               and (last_date (format 'e3')) (char(3))
                    = (Bus_date (format 'e3')) (char(3))
          group by Bus_date, last_date
     )y
     group by last_date;


     
  <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