Login     Register

        Contact Us     Search

XLeratorDB/statistics Documentation

SQL Server sample variance function


 
Updated: 6 August 2010

Use VAR_q to estimate variance based on a sample. To estimate the population variance from a sample of N elements with an unknown mean (the mean being calculated from the sample itself):
 
 VAR
Syntax
SELECT [wctStatistics].[wct].[VAR_q] (
   <@Values_RangeQuery, nvarchar(4000),>)
Arguments
@Values_RangeQuery
the select statement, as text, used to determine the values used in the VAR_q function.
Return Types
float
Remarks
·         If you want measure the population variance, then use the VARP_q function.
·         For simpler queries or for queries on de-normalized data, use the VAR function.
·         No GROUP BY is required for this function even though it produces aggregated results.
Examples
CREATE TABLE #k1(
      [num] [float] NOT NULL
)
INSERT INTO #k1 VALUES (91.3698)
INSERT INTO #k1 VALUES (76.3382)
INSERT INTO #k1 VALUES (74.5692)
INSERT INTO #k1 VALUES (85.2957)
INSERT INTO #k1 VALUES (99.0112)
INSERT INTO #k1 VALUES (86.99)
INSERT INTO #k1 VALUES (70.7837)
INSERT INTO #k1 VALUES (72.834)
INSERT INTO #k1 VALUES (78.1644)
INSERT INTO #k1 VALUES (77.7472)
INSERT INTO #k1 VALUES (66.0627)
INSERT INTO #k1 VALUES (59.781)
INSERT INTO #k1 VALUES (68.4793)
INSERT INTO #k1 VALUES (78.6103)
INSERT INTO #k1 VALUES (59.8621)
 
select wct.VAR_q('SELECT num from #k1')
 

This produces the following result

----------------------
121.668645804095
 
(1 row(s) affected)


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service