Home Page for the TeradataForum
 
https:

Archives of the TeradataForum

Message Posted: Thu, 29 Mar 2007 @ 21:05:13 GMT


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


Subj:   Re: Function for finding minimum among multiple values
 
From:   Prescott, Kyle R

You can use the calendar view or similar structure to normalize the values and take the minimum.

However, if your source table has many rows and many columns you may not want to use cross product join method as it could create a massive spool file.

Example for 5 column comparison:

     select t.groupingcolumns
           ,min (case c.day_of_calendar when 1 then col1
                                        when 2 then col2
                                        when 3 then col3
                                        when 4 then col4
                                        else col5 end) as min_col_value
       from tablename t
            cross join sys_calendar.calendar c
       where c.day_of_calendar <=5
       group by 1;

Kyle Prescott
Unum



     
  <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: 28 Jun 2020