聚合函数 (Entity SQL)
SQL Server .NET Framework 数据提供程序 (SqlClient) 提供聚合函数。聚合函数对一组输入值执行计算并返回一个值。这些函数位于 SqlServer 命名空间中,该命名空间在您使用 SqlClient 时可用。提供程序的命名空间属性使实体框架可以确定此提供程序对特定构造(如类型和函数)使用哪个前缀。
下表显示 SqlClient 聚合函数。
函数 说明
AVG( expression )
返回集合中各值的平均值。
将忽略 Null 值。
参数
Int32、 Int64、Double 和 Decimal。
返回值
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 中不返回)、
Boolean、Double、DateTime、DateTimeOffset、Time、String 或 Binary。
返回值
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 中不返回)、Boolean、Double、DateTime、DateTimeOffset、Time、String 或 Binary。
返回值
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 为以下类型之一:Byte、Int16、Int32、Int64、Byte、Single、Double、Decimal、DateTime、DateTimeOffset、Time、String、Binary。
返回值
expression 的类型。
示例
SELECT VALUE SqlServer.MAX(p.ListPrice)
from AdventureWorksEntities.Product as p
MIN(
相关文档:
Sql代码
--采用SQL语句实现sql2005和Excel 数据之间的数据导入导出,在网上找来一--下,实现方法是这样的:
--Excel---->SQL2005 导入:
select * into useinfo from O ......
操作符优化
IN 操作符
用IN写出来的SQL的优点是比较容易写及清晰易懂,这比较适合现代软件开发的风格。
但是用IN的SQL性能总是比较低的:
数据库试图将其转换成多个表的连接,如果转换不成功则先执行IN里面的子查询,再查询外层的表记录,如果转换成功则直接采用多个表的连接方式查询。由此可见 ......
set autotrace off
set autotrace on
set autotrace traceonly
set autotrace on explain
set autotrace on statistics
set autotrace on explain statistics
set autotrace traceonly explain
set ......
先把程序打开,菜单上 Environment/Examples/Performance Examples 在空白处输入
要执行的程序,注意一定要正确,否则后果很严重,呵呵.
data: itab type table of TRDIR with header line.
select * from TRDIR into table itab
where NAME = 'ZHRRPT1011'.
read table itab with key name = 'ZHRRPT1011'.
......
//在应用程序Open 事件代码中
idle(600)
openbakflag=1
///////////////////////读取配置文件数据库连接设置///////////////////////
string server,datname,datuser,datpsw
server=ProfileString ( "yy.ini","yygl","server", "" )
datname=ProfileString ( "yy.ini","yygl","datname", "" )
datuser=ProfileStrin ......