Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 11 Nov 2008 @ 08:40:18 GMT


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


Subj:   Re: Time interval between events
 
From:   Dieter Noeth

Peter Shvets wrote:

  I have the follwoing table tracking part installation event at a specific location  


          > partID    time_installed    location
          > P1        12/20/2007        L1
          > P1        12/31/2007        L2
          > P1        1/15/2008          L3
          > P2        2/1/2008            L1
          > P2        2/5/2008            L2
          > P2        4/5/2008            L3
          > P3        4/30/2008          L1
          > P3        5/3/2008            L2
  I need to identify how long each part has been installed at each location in SQL. Every next install invalidates the previous one for the same partID.  


     SELECT
        partid,
        COALESCE(MIN(time_installed) OVER
                    (PARTITION BY partid
                     ORDER BY time_installed
                     ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)
                 , CURRENT_DATE)
        - time_installed AS delta,
        location
     FROM tab

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