Login    Register

XLeratorDB/statistics Documentation

MODE


 
Updated: 6 August 2010

Use MODE to return the most common value in a dataset.
Syntax
SELECT [wctStatistics].[wct].[MODE] (
   <@Values_TableName, nvarchar(4000),>
 ,<@ColumnName, nvarchar(4000),>
 ,<@GroupedColumnName, nvarchar(4000),>
 ,<@GroupedColumnValue, sql_variant,>
 ,<@Behavior, float,>)
Arguments
@Values_TableName
the name, as text, of the table or view that contains the values to be used in the MODE calculation.
@ColumnName
the name, as text, of the column in the table or view specified by @Values_TableName that contains the values to be used in the MODE calculation.
@GroupedColumnName
the name, as text, of the column in the table or view specified by @Values_TableName which will be used for grouping the results.
@GroupedColumnValue
the column value to do the grouping on.
@Behavior
identifies how to handle ties.
Return Types
float
Remarks
·         MODE only includes values of type float or of a type that can be implicitly converted to float. All other values and NULL are excluded.
·         If there are no values occurring more than once, MODE returns an error.
·         For more complicated queries consider using the MODE_q function.
·         @Behavior is truncated to zero decimal places.
·         If TRUNC(@Behavior,0) < 0 or TRUNC(@Behavior,0) > 2, MODE returns an an error.
·         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 (5.6)
INSERT INTO #m1 VALUES (4)
INSERT INTO #m1 VALUES (4)
INSERT INTO #m1 VALUES (3)
INSERT INTO #m1 VALUES (2)
INSERT INTO #m1 VALUES (3)
 
select wct.MODE('#m1','num','',NULL,0)

This produces the following result

----------------------
4
 
(1 row(s) affected)
CREATE TABLE #m2(
      [num] [float] NOT NULL
)
INSERT INTO #m2 VALUES (1)
INSERT INTO #m2 VALUES (2)
INSERT INTO #m2 VALUES (3)
INSERT INTO #m2 VALUES (1)
INSERT INTO #m2 VALUES (2)
INSERT INTO #m2 VALUES (3)
 
select wct.MODE('#m2','num','',NULL,0)

This produces the following result

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


  Comments
Add Comment
No Comments Yet


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