| Archives of the TeradataForumMessage Posted: Thu, 07 Feb 2008 @ 09:25:24 GMT
 
 
  
| 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 
 
 |