Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 05 Mar 2013 @ 22:06:59 GMT


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


Subj:   Re: 'Median' value of three dates
 
From:   Prescott, Kyle R

User row_number to order and assign the sequencing, but also add an overall count() over() to count the total items in the window and divide by 2+1. That row sequence equal to the (windowing count / 2 + 1) is the median entry in the list.

You can see from the cumulative count column (ccount_rows) what the median row sequence would be if the sample size wound end at that current row.

     select day_of_calendar
          , row_number() over(partition by month_of_calendar
                         order by year_of_calendar, day_of_calendar)
                         as row_seq
          , count(day_of_calendar) over(partition by month_of_calendar
                         order by month_of_calendar, day_of_calendar
                         rows between unbounded preceding and current row)
                         as ccount_rows
          , ccount_rows / 2 + 1 as median_seq

     from sys_calendar.calendar;

Kyle Prescott | DBA Manager | Unum-GHDS | Chattanooga, TN



     
  <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: 23 Jun 2019