没有合适的资源?快使用搜索试试~ 我知道了~
SQL 函数集合
5星 · 超过95%的资源 需积分: 0 864 下载量 16 浏览量
2008-05-23
08:55:46
上传
评论 1
收藏 399KB DOC 举报
温馨提示
试读
42页
SQL 所 有 函 数
资源详情
资源评论
资源推荐
Sql 函数集合
聚合函数 --------------------------------------------------------------------------------------
时间及日期函数 -----------------------------------------------------------------------------
数学函数 --------------------------------------------------------------------------------------
元数据函数 -----------------------------------------------------------------------------------
字符串函数 -----------------------------------------------------------------------------------
文本和图像函数 -----------------------------------------------------------------------------
配置函数 ---------------------------------------------------------------------------------------
系统函数 ---------------------------------------------------------------------------------------
系统统计函数 ---------------------------------------------------------------------------------
事务、游标、存储过程及触发器 ---------------------------------------------------------
数据库管理 ------------------------------------------------------------------------------------
数据检索、高级检索 ------------------------------------------------------------------------
数据库设计 ------------------------------------------------------------------------------------
MDX 函数 -------------------------------------------------------------------------------------
ODBC API 函数 ------------------------------------------------------------------------------
DB_LIBRARY API 函数 -------------------------------------------------------------------
聚合函数:
1. AVG 返回组中的平均值,空值将被忽略。
例如:use northwind // 操作 northwind 数据库
Go
Select avg (unitprice) //从表中选择求 unitprice 的平均值
From products
Where categoryid = ‘8’
2. BINABY_CHECKSUM 可用于检测表中行的更改
返回值由表达式的运算结果类型决定
例如:use northwind
Go
Create table tablebc(productid int,bchecksum int) //建立有两个属性的表
Insert into tablebc //向表中插入数据
Select priductid,binary_checksum(*)
From products
Update products //更新
Set productname=’oishi tofu’, unitprice=20 where productname = ‘tofu’
Update products //更新
Set priductname=’oishi konbu’, unitprice = 5 where priductname=’konbu’
Update priducts //更新
Set prodctname=’oishi genen shouyu’, unitprice =12
Where priductname=’genen shouyu’
Select productid //挑出变化的行
From tablebc
Where exists (
Select productid from products
Where product.productid = tablebc.productid and
binary_checksu (*) <> tablebc.bchecksum) //标志出变化的行
3. CHECKSUM 返回在表的行上或在表达式上计算的校验值 CHECKSUM 用于生成
哈希索引
例如:
Set arithabort on
Use northwind
Go
Alter table products
Add cs_pname as checksum(productname) //在参数列是添加一个校验值
Create imdex pname_index on products(cs_pname) //生成索引
Go
Select top 5 cs_pname from products order by cs_pname desc //选择根据索引
列的前 5 个 cs_pname
4.Checksum_agg 返回组中值的校验值。空值冽被忽略。
例如:
Use northwind
Go
Select checksum_agg(cast(unitsinstock as int)) //检测 products 表的 unitsinstock 列
的更改
from products
5.Count 返回组中项目的数量
例如:
例一:
Use pubs
Go
Select count(distinct city) //对 city 中的每一行都计算,并返回非空的数量
From authors
Go
例二:
Use pubs
Go
Select count(*) // 返回组中项目的数量
From titles
Go
例三:
Use pubs
Go
Select count(*),avg(price) // 选择 advance 大于$1000 的总数和平均 price
From titles
Where advance >$1000
Go
6.Count_big 返回组中项目的数量。在使用上和 count 基本上是一样的,只是在返回值上
有一点区别,count_big 返回是 bigint 的数据类型值,count 返回的是 int 数据
类型值。
7.Grouping 返回一个聚合函数,它产生一个附加列,当用 CUBE 或 ROLLUP 运算符添加
行时,附加 的列输出值为 1,当所添加的行不是由 CUBE 或 ROLLUP 产生
时,附加列值为 0
例如:
Use pubs
Go
Select royalty,sum(advance) ‘total advance’, //选择列 royalty,聚合 advance 数值
Grouping(royalty) ‘grp’ //grouping 函数
From titles
Group by royalty with rollup //group by 与 rollup 相联系产生分组
8.Max 返回表达式的最大值
例如:
Use pubs
Go
Select max(ytd_sales) //选择 ytd_sales 列属性,求其最大值。
From titles
Go
9.Min 返回表达式的最小值
例如:
Use pubs
Go
Select min(ytd_sales) //选择 ytd_sales 列属性,求其最小值。
From titles
Go
10.Stdev 返回给定表达式中所有值的统计标准偏差。
例如:
Use pubs
Select stdev(royalty)
From titles
11.Stdevp 返回给定表达式中所有值的填充统计标准偏差。
例如:
Use pubs
Select stdev(royalty)
From titles
12.sum 返回表达式中所有值的的和,或只返回 DISTINCT 值。SUM 只能用数字列。
例如:
Use pubs
Go
Select type,sum(price),sum(advance) //选择 type,price 的和,advance 的和
From titles
Where type like ‘%cook’ //匹配结尾字符为 cook
Group by type
Order by type
Go
例如 2:
Use pubs
Go
Select type,price,advance
From titles
Where type like’%cook’
Order by type
Compute sum(price),sum(advance) by type //根据 type 的属性计算 price 和 advance
的和
13.Var 返回给定表达式中所有值的统计方差。
例如:
Use pubs
Go
Selecdt var(royalty)
From titles
14.Varp 返回给定表达式中所有值的填充的统计方差
例如:
Use pubs
Go
Select varp(royalty)
From titles
剩余41页未读,继续阅读
x37623412
- 粉丝: 1
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论10