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中可以使用Like进行模糊查询,例如 f_stuname like 'a%' 查询f_stuname列以a开头的记录。
当我们在应用中使用
f_stuname
like '%a%' 时,如果
f_stuname有索引的话,这个索引也是不执行的
在SQL优化中这个写法就是一个不好的SQL了。
那么如何来替换这个呢,这一个就用到了Oracle的instr函数了
我们可以这样 ......
我说的不定条件是指查询条件的个数不定。有时一个,有时两个,有时好几个。
首先我发现
select * from A where a='kkk' 与
select * from A where a like 'kkk'
其实效果是一样,只要 like 后面的字符串不包含通配符。这样一来就很方便了。譬如有
select * from A where a='KKK' and b='LLL'
有两个查询条件, ......
**************************************
**** sql 查询备忘 &nb ......
SQL注入攻击的危害性很大。在讲解其防止办法之前,数据库管理员有必要先了解一下其攻击的原理。这有利于管理员采取有针对性的防治措施。
一、 SQL注入攻击的简单示例。
statement := "SELECT * from Users WHERE Value= " + a_variable + "
上面这条语句是很普通的一条SQL语句,他主要实 ......