第四节 SQL 系统函数、通配符like、between、in关键字、聚合函数

View Code
--系统函数

--数据类型转换

selectconvert(varchar(5),12345)

selectconvert(int,'12345')


--当前数据库用户

selectcurrent_user


--返回字符的字节数

selectdatalength('中华人民共和国')


--返回当前OS的计算机名

selectHost_Name()


--当前SQLSever的登录名

selectsystem_user


--根据指定数值获取当前数据的用户名

selectuser_name(1)

selectuser_name(2)

selectuser_name(3)

selectuser_name(4)

selectuser_name(5)


--通配符必须配合like(模糊查询)关键字来使用

--通配符:_、%、[0-9] [a-z] [035],[^035]

select*from Students where SName like'张%'


--范围查询between

select*from StuMark 

where Score between 60 and 80

select*from Students 

where age between 10 and 21

--in关键字

select*from Students where address 

in('浙江金华','河北','')


select*from Students 

where address notin('浙江金华','河北') 


--聚合函数

--sum:计算总和

selectsum(Score)as总成绩from StuMark


selectsum(Score)as C#总成绩from StuMark

where CourseID=1


--avg:计算平均值

selectsum(Score)as总成绩,avg(Score)as平均分

from StuMark


--max、min:最大值、最小值

selectsum(Score)as总成绩,avg(Score)as平均分,

max(Score)as最高分,min(Score)as最低分

from StuMark


--count:计数

selectsum(Score)as总成绩,avg(Score)as平均分,

max(Score)as最高分,min(Score)as最低分,

count(*)as考试人数

from StuMark where CourseID=1

 

posted @ 2012-06-24 10:21  ComBat  阅读(146)  评论(0编辑  收藏  举报