加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

聚合函数 (Entity SQL)

发布时间:2020-12-13 20:29:59 所属栏目:百科 来源:网络整理
导读:SQL Server .NET Framework 数据提供程序 (SqlClient) 提供聚合函数。聚合函数对一组输入值执行计算并返回一个值。这些函数位于 SqlServer 命名空间中,该命名空间在您使用 SqlClient 时可用。提供程序的命名空间属性使实体框架可以确定此提供程序对特定构造

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 版本的相应文档:

SQL Server 2000 SQL Server 2005 SQL Server 2008

Aggregate Functions (Transact-SQL)(聚合函数 (Transact-SQL))

Aggregate Functions (Transact-SQL)(聚合函数 (Transact-SQL))

Aggregate Functions (Transact-SQL)(聚合函数 (Transact-SQL))

另请参见

参考

聚合规范函数 (Entity SQL)

概念

Entity SQL 语言

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读