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
相关文档:
1.SQL SERVER的数据类型
数据类弄是数据的一种属性,表示数据所表示信息的类型。任何一种计算机语言都定义了自己的数据类型。当然,不同的程序语言都具有不同的特点,所定义的数据类型的各类和名称都或多或少有些不同。SQLServer 提供了 25 种数据类型:
·Binary [(n)]
·Varbinary [(n)]
......
从博客园中看到一篇文章,介绍大软件公司面试时常常会出的两道SQL题(见附录)。
我觉得受益很多,在此之前,我一直觉得,SQL2008似乎提供了这方面的支持,但更低的版本,包括2005,非游标做不出来(水平够菜)。总结心得如下:
1、 强大的group by
1 select stdname,
2 isnull(sum( ......
protected void Button1_Click(object sender, EventArgs e)
{
string strsql = "select * from TreeViewTemp where parentID=0";
DataTable dt = db.GetDataTable(strsql);
StringWriter sw = new StringWriter();
//StreamWriter sw = new Strea ......
--
SQL Server Split函数
--
Author:zc_0101
--
说明:
--
支持分割符多字节
--
使用方法
--
Select * from DBO.F_SQLSERVER_SPLIT('1203401230105045','0')
--
select * from DBO.F_SQLSERVER_SPLIT('abc1234a12348991234',' ......
SQL注入攻击的危害性很大。在讲解其防止办法之前,数据库管理员有必要先了解一下其攻击的原理。这有利于管理员采取有针对性的防治措施。
一、 SQL注入攻击的简单示例。
statement := "SELECT * from Users WHERE Value= " + a_variable + "
上面这条语句是很普通的一条SQL语句,他主要实 ......