聚合函数 (Entity SQL)

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

下表显示 sqlClient 聚合函数

函数 说明

AVG( expression )

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

将忽略 Null 值。

参数

Int32 Int64DoubleDecimal

返回值

expression 的类型。

示例

SELECT VALUE sqlServer.AVG(p.ListPrice) FROM

AdventureWorksEntities.Product as p

CHECKSUM_AGG( collection )

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

将忽略 Null 值。

参数

集合 (Int32)。

返回值

Int32

示例

SELECT VALUE sqlServer.Checksum_Agg(cast(product.ListPrice as Int32))

FROM AdventureWorksEntities.Product AS product

where product.ListPrice > cast(2.0 as Decimal)

COUNT( expression )

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

参数

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

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

BooleanDoubleDateTimeDateTimeOffsetTimeStringBinary

返回值

Int32

示例

anyelement(SELECT VALUE sqlServer.COUNT(product.ProductID)

FROM AdventureWorksEntities.Product AS product

WHERE sqlServer.CEILING(product.ListPrice) ==

sqlServer.FLOOR(product.ListPrice))

COUNT_BIG( expression )

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

参数

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

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

返回值

Int64

示例

SELECT VALUE sqlServer.COUNT_BIG(product.ProductID)

FROM AdventureWorksEntities.Product 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.Product as p

MIN( expression )

返回集合中的最小值。

参数

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

Binary

返回值

expression 的类型。

示例

SELECT VALUE sqlServer.MIN(p.ListPrice)

FROM AdventureWorksEntities.Product as

STDEV( expression )

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

参数

集合 (Double)。

返回值

Double

示例

SELECT VALUE sqlServer.STDEV(product.ListPrice)

FROM AdventureWorksEntities.Product AS product

where product.ListPrice > cast(2.0 as Decimal)

STDEVP( expression )

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

参数

集合 (Double)。

返回值

Double

示例

SELECT VALUE sqlServer.STDEVP(product.ListPrice)

FROM AdventureWorksEntities.Product AS product

where product.ListPrice > cast(2.0 as Decimal)

SUM( expression )

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

参数

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

返回值

expression 的类型。

示例

SELECT VALUE sqlServer.SUM(p.ListPrice)

FROM AdventureWorksEntities.Product as p

VAR( expression )

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

参数

集合 (Double)。

返回值

Double

示例

SELECT VALUE sqlServer.VAR(product.ListPrice)

FROM AdventureWorksEntities.Product AS product

where product.ListPrice > cast(2.0 as Decimal)

VARP( expression )

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

参数

集合 (Double)。

返回值

Double

示例

SELECT VALUE sqlServer.VARP(product.ListPrice)

FROM AdventureWorksEntities.Product AS product

where product.ListPrice > cast(2.0 as Decimal)

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

另请参见

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...