Login    Register

XLeratorDB/statistics Documentation

MEDIAN_q


 
Updated: 6 August 2010

Use MEDIAN_q to return the median of the given numbers. The median is the number in the middle of a set of numbers.
Syntax
SELECT [wctStatistics].[wct].[MEDIAN_q] (
   <@Values_RangeQuery, nvarchar(4000),>)
Arguments
@Values_RangeQuery
the select statement, as text, used to determine the values to be used in the MEDIAN_q calculation.
Return Types
float
Remarks
·         If there is an even number of numbers in the set, then MEDIAN_q calculates the average of the two numbers in the middle.
·         MEDIAN_q only includes values of type float or of a type that can be implicitly converted to float. All other values and NULL are excluded.
·         For simpler queries consider using the MEDIAN function.
·         No GROUP BY is required for this function even though it produces aggregated results.
Examples
CREATE TABLE #m1(
      [num] [float] NOT NULL
)
INSERT INTO #m1 VALUES (1)
INSERT INTO #m1 VALUES (2)
INSERT INTO #m1 VALUES (4)
INSERT INTO #m1 VALUES (7)
INSERT INTO #m1 VALUES (8)
INSERT INTO #m1 VALUES (9)
INSERT INTO #m1 VALUES (10)
INSERT INTO #m1 VALUES (12)
 
select wct.MEDIAN_q('select num from #m1')

This produces the following result

----------------------
7.5
 
(1 row(s) affected)


  Comments
Add Comment
No Comments Yet


 |  View Topic History  |
Copyright 2010 WestClinTech LLC         Privacy Policy        Terms of Service