实验报告一文档格式.docx

上传人:b****4 文档编号:16397133 上传时间:2022-11-23 格式:DOCX 页数:13 大小:161.17KB
下载 相关 举报
实验报告一文档格式.docx_第1页
第1页 / 共13页
实验报告一文档格式.docx_第2页
第2页 / 共13页
实验报告一文档格式.docx_第3页
第3页 / 共13页
实验报告一文档格式.docx_第4页
第4页 / 共13页
实验报告一文档格式.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

实验报告一文档格式.docx

《实验报告一文档格式.docx》由会员分享,可在线阅读,更多相关《实验报告一文档格式.docx(13页珍藏版)》请在冰豆网上搜索。

实验报告一文档格式.docx

2、运算符的应用

A、比较运算符

useteaching

go

select*fromstudentwherebirthday>

1989-01-01'

select*fromteacherwheredepartment<

>

计算机学院'

B、逻辑运算符

select*fromscorewherestudentnolike'

09%'

andfinalbetween60and90

------------------------

select*fromteacherwhereprofin('

教授'

'

副教授'

C、“+”号运算符:

declare@achar(5),@bvarchar(5),@cint,@ddecimal(5,2)

select@a='

123'

@b='

@c=321,@d=

print@a+@b

print@a+@d

print@c+@d

数据库'

程序开发'

D、位运算符

declare@aint,@bint

select@a=5,@b=12

select@a&

@b,@a|@b,@a^@b,~@a

E、数学函数

selectceiling,ceiling,ceiling的左边

selectround,0),round,0,1)

F、时间日期函数

declare@birthdaydatetime

set@birthday='

1989-08-21'

select@birthdayas'

生日'

datediff(year,@birthday,getdate())as'

年龄'

selectgetdate()as'

当前日期'

year(getdate())as'

年份'

datepart(month,getdate())as'

月份'

datename(day,getdate())as'

日期'

G、转换函数

declare@countint,@datedatetime

select@count=255,@date=getdate()

print'

变量count的值为:

+cast(@countasvarchar(5))

printcast('

2009-7-07'

assmalldatetime)+100

printconvert(varchar(10),@date,102)

H、字符函数

declare@strasnchar(25)

set@str='

SQLSERVER2005数据库应用与开发'

selectlen(@str),charindex('

库应用'

@str),substring(@str,5,6),replace(@str,'

开发'

设计'

),lower(@str),ascii(@str)

3、编写程序,根据姓名查询teaching数据库中学生的基本信息和选课信息,学生姓名通过变量输入。

对于不存在的学生姓名输入值,打印提示信息。

declare@snamenchar(8)

set@sname='

许海冰'

ifexists(select*fromstudentwheresname=@sname)

selectstudent.*,courseno,usually,finalfromstudent,score

where=andsname=@sname

else

提示:

不存在姓名为'

+rtrim(ltrim(@sname))+'

的学生资料'

4、编写程序,查询所以学生选修课的期末成绩和对应等级,如学生末选修任何课程则输出提示信息。

select,sname,cname,final,

case

whenfinal>

=90then'

优'

=80then'

良'

=70then'

中'

=60then'

及格'

whenfinal<

60then'

不及格'

whenfinalisnullthen'

未选修任何课程'

endaslevel

fromstudentleftjoinscoreon=leftjoincourseon=

5、编写程序,判断字符变量@ch中存放的是字母字符、数字字符还是其他字符,并输出相关的信息。

declare@chchar

select@ch='

d'

ifupper(@ch)>

='

A'

andupper(@ch)<

Z'

print@ch+'

是字母字符'

elseif@ch>

0'

and@ch<

9'

是数字字符'

else

是其他字符'

当@ch='

3'

时,

#'

6、编写程序,判断某个年份是否为闰年,年份由变量输入。

declare@yearint

set@year=year(getdate())

if@year%4=0

begin

if@year%100=0

begin

if@year%400=0

printcast(@yearaschar(4))+'

年是闰年'

else

不年是闰年'

end

else

printcast(@yearaschar(4))+'

end

printcast(@yearaschar(4))+'

7、编写程序,输出在1~3000之间能被17整除的最大数值。

declare@sint,@iint

select@s=0,@i=3000

while@i>

1

begin

if@i%17=0

print'

1~3000之间能被整除的最大数值为:

+cast(@iaschar(4))

break

set@i=@i-1

End

8、查询所有课程的课程编号、课程号和学分

selectcourseno,cname,credit

fromcourse

9、查询‘090501’班的所有学生的基本信息。

select*fromstudentwhereclassno='

090501'

10、查询student表中所有年龄大于20岁的男生的名字和年龄。

selectsname,datediff(year,birthday,getdate())asage

fromstudent

wheredatediff(year,birthday,getdate())>

20andsex='

11、查询计算机学院教师的专业名称。

selectdistinctmajor

fromteacher

wheredepartment='

12、查询选修课程且期末成绩不为空的学生人数。

selectcount(distinctstudentno)as'

选修课程学生的人数'

fromscorewherefinalisnotnull

13、查询Email使用126邮箱的所有学生的学号、姓名和电子邮箱地址。

selectstudentno,sname,emailfromstudent

whereemaillike'

%'

14、查询每名学生的学号、选修课程数目、总成绩,并将查询结果存放到生成的“学生选课统计表”.

方法一:

createtable学生选课统计表

studentnonchar(10)notnull,

amountsmallintnull,

sumsmallintnull,

insertinto学生选课统计表

select,count(courseno)as'

选修课程数目'

sum(final)as'

总成绩'

fromstudentleftjoinscoreon=

groupby

方法二:

selectstudentno,count(courseno)as'

into学生选课统计表

fromscore

groupbystudentno

-------------------------------------

select*from学生选课统计表

selectsname,courseno,final

fromstudent,score

where(courseno='

c05109'

orcourseno='

c05103'

)and=

andfinalbetween90and100

15、查询score表中选修‘c05109’或‘c05103’课程,并且课程期末成绩在90~100分之间的学生姓名和期末成绩。

selectsname,final

fromscore,student

wherefinalbetween90and100andcoursenoin('

16、查询student表中所有学生的基本信息,查询结果按班级号classno升序排序,同一班级中的学生按入学成绩point降序排列。

select*fromstudent

orderbyclassnoasc,pointdesc

17、查询选修‘c05109’课程,并且期末成绩在5名的学生学号、课程号和期末成绩。

selecttop2studentno,courseno,final

wherecourseno='

orderbyfinaldesc

18、查询各班学生的人数。

selectclassno,count(*)

groupbyclassno

19、查询各班期末成绩的最高分和最低分。

selectcourseno,max(final)as'

最高分'

min(final)as'

最低分'

wherefinalisnotnull

groupbycourseno

20、查询教授两门及以上课程的教师编号、课程编号和任课班级。

selectteacherno,courseno,classno

fromteach_class

whereteachernoin(

selectteacherno

fromteach_class

groupbyteacherno

havingcount(*)>

=2)

21、查询课程编号以‘c05’开头、被3名及以上学生选修且期末成绩的平均分高于75分的课程号、选修人数和期末成绩平均分,并按平均分降序排序。

selectcourseno,count(studentno)as'

人数'

avg(final)as'

平均成绩'

wherecoursenolike'

c05%'

andfinalisnotnull

havingcount(studentno)>

=3andavg(final)>

=75

22、查询所有08级学生的期末成绩平均分,要求利用COMPUTEBY方法显示每一名学生编号、课程号、期末成绩的明细表,以及期末成绩平均分的汇总表

selectstudentno,courseno,final

wherestudentnolike'

08%'

orderbystudentno

computeavg(final)bystudentno

23、查询所有女生入学成绩的最高分,要求利用COMPUTEBY方法既显明细有显示汇总结果。

select*

wheresex='

女'

computemax(point)

四、实验报告总结

(1)、局部变量俩种赋值方法及区别。

赋值时需要使用SET和SELECT命令。

与SELECT命令相比,SET命令一次只能为一个变量赋值,而SELECT命令可以同时多个变量赋值。

(2)、数据类型的隐式转换和显示转换。

隐式转换:

SQLServer2005可以自动对某些表达式进行转换,这种转换称为隐式转换。

转换时不必使用CAST或CONVERT来进行隐式转换。

显示转换:

使用CAST或CONVERT函数可以将一种数据类型的表达式强制转换为另一种数据类型。

(3)、GROUPBY子句中分组依据表达式与SELECT子句中选择列表的对应关系。

当使用GROUPBY子句时,出现在查询的SELECT列表中的每一列都必须同时出现在GROUPBY子句中。

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 营销活动策划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1