Aggregate Functions
The .NET Framework Data Provider for SQL Server (SqlClient) provides aggregate functions. Aggregate functions perform calculations on a set of input values and return a value. These functions are in the SqlServer namespace, which is available when you use SqlClient. A provider's namespace property allows the Entity Framework to discover which prefix is used by this provider for specific constructs, such as types and functions.
The following table shows the SqlClient aggregate functions.
Function | Description |
---|---|
AVG(expression) |
Returns the average of the values in a collection. Null values are ignored. Arguments An Int32, Int64, Double, and Decimal. Return Value The type of expression. Example
|
CHECKSUM_AGG(collection) |
Returns the checksum of the values in a collection. Null values are ignored. Arguments A Collection (Int32). Return Value An Int32. Example
|
COUNT(expression) |
Returns the number of items in a collection as an Int32. Arguments A Collection (T) where T is one of the following types: Guid (not returned in SQL Server 2000), Boolean, Double, DateTime, DateTimeOffset, Time, String, or Binary. Return Value An Int32. Example
|
COUNT_BIG(expression) |
Returns the number of items in a collection as a bigint. Arguments A Collection (T) where T is one of the following types: Guid (not returned in SQL Server 2000), Boolean, Double, DateTime, DateTimeOffset, Time, String, or Binary. Return Value An Int64. Example
|
MAX(expression) |
Returns the maximum value the collection. Arguments A Collection (T) where T is one of the following types: Byte, Int16, Int32, Int64, Byte, Single, Double, Decimal, DateTime, DateTimeOffset, Time, String, Binary. Return Value The type of expression. Example
|
MIN(expression) |
Returns the minimum value in a collection. Arguments A Collection (T) where T is one of the following types: Byte, Int16, Int32, Int64, Byte, Single, Double, Decimal, DateTime, DateTimeOffset, Time, String, Binary. Return Value The type of expression. Example
|
STDEV(expression) |
Returns the statistical standard deviation of all values in the specified expression. Arguments A Collection (Double). Return Value A Double. Example
|
STDEVP(expression) |
Returns the statistical standard deviation for the population for all values in the specified expression. Arguments A Collection (Double). Return Value A Double. Example
|
SUM(expression) |
Returns the sum of all the values in the collection. Arguments A Collection (T) where T is one of the following types: Int32, Int64, Double, Decimal. Return Value The type of expression. Example
|
VAR(expression) |
Returns the statistical variance of all values in the specified expression. Arguments A Collection (Double). Return Value A Double. Example
|
VARP(expression) |
Returns the statistical variance for the population for all values in the specified expression. Arguments A Collection (Double). Return Value A Double. Example
|
For more information about the aggregate functions that SqlClient supports, see the documentation for the SQL Server version that you specified in the SqlClient provider manifest:
SQL Server 2000 | SQL Server 2005 | SQL Server 2008 |
---|---|---|