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函数了
我们可以这样 ......
从博客园中看到一篇文章,介绍大软件公司面试时常常会出的两道SQL题(见附录)。
我觉得受益很多,在此之前,我一直觉得,SQL2008似乎提供了这方面的支持,但更低的版本,包括2005,非游标做不出来(水平够菜)。总结心得如下:
1、 强大的group by
1 select stdname,
2 isnull(sum( ......
**************************************
**** sql 查询备忘 &nb ......
SQL字符串函数
要看a的ASCII码,sql语句
select ascii(a)
要看ASCII码为56的字符
select char(56)
ASCII() --函数返回字符表达式最左端字符的ASCII 码值
CHAR() --函数用于将ASCII 码转换为字符
--如果没有输入0 ~ 255 之间的ASCII 码值CHAR 函数会返回一个NULL 值
LOWER() --函数把字符串全部转换为小写
UPPER() ......
sql server 创建索引
http://54laobaixing.blog.163.com/blog/static/57843681200952411133121/
SQL SERVER索引,优化
http://tieba.baidu.com/f?kz=170889655
Sybase SQL Server索引的使用和优化
http://www.yesky.com/79/211079.shtml ......