|
|
Archives of the TeradataForum
Message Posted: Wed, 27 Nov 2002 @ 12:03:38 GMT
Subj: | | Re: MEDIAN - using SQL |
|
From: | | Claybourne L. Barrineau |
Try this for a median function:
Select Average(averageresult.ColumnA)
From (
Select Distinct csumlist.ColumnA
From (
Select Case When TotalCount mod 2 = 0 Then TotalCount/2
Else TotalCount/2 + 1
End
, TotalCount/2 + 1
From (Select Count(ColumnA) From TableA) TblCount (TotalCount)
) csumrange (LowMiddle, HighMiddle)
,
(
Select csum(1,ColumnA asc)
, ColumnA
From TableA
) csumlist (CSUMvalue, ColumnA)
Where csumlist.CsumValue >= csumrange.LowMiddle
and csumlist.CsumValue <= csumrange.HighMiddle
) AverageResult (ColumnA)
TableA = Your Table
ColumnA= Your Column
Hope this helps,
Claybourne Barrineau
| |