Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 07 Feb 2008 @ 09:25:24 GMT


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


Subj:   Re: How to code a join or restructure table?
 
From:   Dieter Noeth

Michael Larkins wrote:

          > select rateid,
          >         name,
          >         rate
          >  from rates
          > qualify .1653 between amount and
          >      max(amount) over(partition by name
          >                              order by amount
          >                               rows between 0 preceding
          >                                        and 1 following)

Try .1599 :-)

     SELECT *
     FROM rates
     WHERE amount < .1653
     QUALIFY
        RANK() OVER (PARTITION BY name
                     ORDER BY amount DESC) = 1

I do it all the time to find the "current" row for any given date.


Dieter



     
  <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