---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------
1、几个简单的基本的sql语句:
选择:select * from table1where 范围
插入:insert intotable1(field1,field2) values(value1,value2)
删除:delete from table1where 范围
更新:update table1 setfield1=value1 where 范围
查找:select * from table1 where field1 like’%value1%’
排序:select * from table1 order by field1,field2[desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
2、几个高级查询运算词:
A: UNION 运算符
UNION 运算符通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表。当 ALL 随 UNION 一起使用时(即 UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自 TABLE1 就是来自 TABLE2。
B: EXCEPT 运算符
EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL),不消除重复行。
C: INTERSECT 运算符
INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。
注:使用运算词的几个查询结果行必须是一致的。
3、SQL SERVER中直接循环写入数据
declare @i int
set @i=1
while @i<30
begin
insert into test (userid) values(@i)
set @i=@i+1
end
4、字符串函数:
1.datalength(Char_expr) 返回字符串包含字符数,但不包含后面的空格
2.substring(expression,start,length) 取子串,字符串的下标是从“1”,start为起始位置,length为字符串长度,实际应用中以len(expression)取得其长度
3.right(char_expr,int_expr) 返回字符串右边第int_expr个字符,还用left于之相反
4.isnull( check_expression , replacement_value )如果check_expression为空,则返回replacement_value的值,不为空,就返回check_expression字符操作类
5、比较A,B表是否相等:
if (select checksum_agg(binary_checksum(*)) from A)
=
(select checksum_agg(binary_checksum(*)) from B)
print '相等'
else
print '不相等'
6、有如下表,要求就表中所有沒有及格的成绩,在每次增长0.1的基础上,使他们刚好及格:
Name score
Zhangshan 80
Lishi 59
Wangwu 50
Songquan 69
while((select min(score) from tb_table)<60)
begin
update tb_table set score =score*1.01
where score<60
if (select min(score) from tb_table)>60
break
else
continue
end
---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------
详细请查看:http://net.itheima.com/