SQL聚合函
SQL聚合函
标签:sql聚合函数 杂谈
聚合函数:
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
相关文档:
SQL:1999连接
SQL:1999连接在语法上和传统的ORACLE连接有着很大的不同。SQL:1999连接的类型在from语句中指明。ORACLE 9I支持的SQL:1999连接包括:
l CROSS连接
l NATURAL连接
l ......
从博客园中看到一篇文章,介绍大软件公司面试时常常会出的两道SQL题(见附录)。
我觉得受益很多,在此之前,我一直觉得,SQL2008似乎提供了这方面的支持,但更低的版本,包括2005,非游标做不出来(水平够菜)。总结心得如下:
1、 强大的group by
1 select stdname,
2 isnull(sum( ......
最近刚学会在VB2008 中使用参数化SQL语句,于是马上用到代码中,却碰到查不到任何数据的情况,纠结了好几天,还是没有搞明白,差点吐血。不得已还是先在代码中使用字符串拼接的SQL语句。
包含参数化SQL语句的代码如下:
Dim cmSl As N ......
我说的不定条件是指查询条件的个数不定。有时一个,有时两个,有时好几个。
首先我发现
select * from A where a='kkk' 与
select * from A where a like 'kkk'
其实效果是一样,只要 like 后面的字符串不包含通配符。这样一来就很方便了。譬如有
select * from A where a='KKK' and b='LLL'
有两个查询条件, ......
SQL注入攻击的危害性很大。在讲解其防止办法之前,数据库管理员有必要先了解一下其攻击的原理。这有利于管理员采取有针对性的防治措施。
一、 SQL注入攻击的简单示例。
statement := "SELECT * from Users WHERE Value= " + a_variable + "
上面这条语句是很普通的一条SQL语句,他主要实 ......