聚合函数 (Entity SQL)

SQL Server .NET Framework 数据提供程序 (SqlClient) 提供聚合函数。 聚合函数对一组输入值执行计算并返回一个值。 这些函数位于 SqlServer 命名空间中,该命名空间在您使用 SqlClient 时可用。 提供程序的命名空间属性使实体框架可以确定此提供程序对特定构造(如类型和函数)使用哪个前缀。

下表显示 SqlClient 聚合函数。

功能 说明

AVG( expression )

返回集合中各值的平均值。

null 值将被忽略。

参数

Int32Int64DoubleDecimal

返回值

expression 的类型。

示例

SELECT VALUE SqlServer.AVG(p.ListPrice) FROM 
AdventureWorksEntities.Products as p 

CHECKSUM_AGG( collection )

返回集合中各值的校验和。

null 值将被忽略。

参数

集合 (Int32)。

返回值

Int32

示例

SELECT VALUE SqlServer.Checksum_Agg(cast(product.ListPrice as Int32)) 
FROM AdventureWorksEntities.Products AS product 
WHERE product.ListPrice > cast(@price as Decimal) 

COUNT( expression )

Int32 形式返回集合中的项数。

参数

集合 (T),其中 T 为以下类型之一:

Guid(在 SQL Server 2000 中不返回)、

BooleanDoubleDateTimeDateTimeOffsetTimeStringBinary

返回值

Int32

示例

ANYELEMENT(SELECT VALUE SqlServer.COUNT(product.ProductID) 
FROM AdventureWorksEntities.Products AS product 
WHERE SqlServer.CEILING(product.ListPrice) == 
SqlServer.FLOOR(product.ListPrice)) 

COUNT_BIG( expression )

bigint 形式返回集合中的项数。

参数

集合 (T),其中 T 为以下类型之一:

Guid(在 SQL Server 2000 中不返回)、BooleanDoubleDateTimeDateTimeOffsetTimeStringBinary

返回值

Int64

示例

ANYELEMENT(SELECT VALUE SqlServer.COUNT_BIG(product.ProductID) 
FROM AdventureWorksEntities.Products AS product 
WHERE SqlServer.CEILING(product.ListPrice) == 
SqlServer.FLOOR(product.ListPrice)) 

MAX( expression )

返回集合中的最大值。

参数

集合 (T),其中 T 为以下类型之一:ByteInt16Int32Int64ByteSingleDoubleDecimalDateTimeDateTimeOffsetTimeStringBinary

返回值

expression 的类型。

示例

SELECT VALUE SqlServer.MAX(p.ListPrice) 
FROM AdventureWorksEntities.Products as p

MIN( expression )

返回集合中的最小值。

参数

集合 (T),其中 T 为以下类型之一:ByteInt16Int32Int64ByteSingleDoubleDecimalDateTimeDateTimeOffsetTimeString

Binary.

返回值

expression 的类型。

示例

SELECT VALUE SqlServer.MIN(p.ListPrice) 
FROM AdventureWorksEntities.Products as p

STDEV( expression )

返回指定表达式中所有值的统计标准偏差。

参数

集合 (Double)。

返回值

一个 Double

示例

SELECT VALUE SqlServer.STDEV(product.ListPrice) 
FROM AdventureWorksEntities.Products AS product 
WHERE product.ListPrice > cast(@price as Decimal) 

STDEVP( expression )

返回指定表达式中所有值的总体标准偏差。

参数

集合 (Double)。

返回值

一个 Double

示例

SELECT VALUE SqlServer.STDEVP(product.ListPrice) 
FROM AdventureWorksEntities.Products AS product 
WHERE product.ListPrice > cast(@price as Decimal) 

SUM( expression )

返回集合中所有值的总和。

参数

集合 (T),其中 T 为以下类型之一:Int32Int64DoubleDecimal

返回值

expression 的类型。

示例

SELECT VALUE SqlServer.SUM(p.ListPrice) 
FROM AdventureWorksEntities.Products as p

VAR( expression )

返回指定表达式中所有值的方差。

参数

集合 (Double)。

返回值

一个 Double

示例

SELECT VALUE SqlServer.VAR(product.ListPrice) 
FROM AdventureWorksEntities.Products AS product 
WHERE product.ListPrice > cast(@price as Decimal) 

VARP( expression )

返回指定表达式中所有值的总体方差。

参数

集合 (Double)。

返回值

一个 Double

示例

SELECT VALUE SqlServer.VARP(product.ListPrice) 
FROM AdventureWorksEntities.Products AS product 
WHERE product.ListPrice > cast(@price as Decimal) 

有关 SqlClient 支持的聚合函数的更多信息,请参见 SqlClient 提供程序清单中所指定的 SQL Server 版本的相应文档:

SQL Server 2000 SQL Server 2005 SQL Server 2008

聚合函数 (Transact-SQL)

聚合函数 (Transact-SQL)

聚合函数 (Transact-SQL)

另请参见

参考

聚合规范函数 (Entity SQL)

概念

Entity SQL 语言