Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 30 Apr 2008 @ 17:49:06 GMT


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


Subj:   Re: Retrieving the Second Highest Amount
 
From:   Sonje, Zdravko

Megan, you can run two statements and then use union to get desired records.

with this you get second highest record:

     select max(amount), customer from table where (amount, customer) not in
     (select max(amount), customer from table group by customer) and date =
     some_date group by customer

and from this you get record where there is only one:

     select a.* from (
     select max(amount) mymax, min(amount) mymin, customer from table where
     date = some_date group by customer
     ) a
     where mymax = mymin

Thanks,

Zdravko Sonje



     
  <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