print@name1+cast(@scoreaschar(3))
ifexists(select*fromsysobjectswherename='qqA') droptableqqA createtableqqA ( )
ifexists(select*fromsysobjectswherename='qqB') droptableqqB createtableqqB ( )
--create table qqB --(
-- id intidentity(1,1) primary key, -- qnoint references qqA(qno) --)
declare@datadatetime select@data=max(ExanDate) fromResultinnerjoinSubject
onResult.SubjectNo=Subject.SubjectNo whereSubjectName='Java Logic'; --print @data
declare@myavgdecimal(5,2) select@myavg=avg(StudentResult) fromResultinnerjoinSubject
onResult.SubjectNo=Subject.SubjectNo
idintidentity(1,1)primarykey, qnoint,
phonechar(11)check(len(phone)=11) foreignkey (qno)referencesqqA(qno), --check(len(phone)=11)
--constraint CK_qqA_phone check(len(phone)=11) qnointprimarykey,
qnamenvarchar(10)default ('zhangsan')
whereSubjectName='Java Logic'andExanDate=@data
print'平均值:'+convert(varchar(5),@myavg)
if(@myavg>70)
========================================================================== --? 统计并显示最近的一次Java Logic考试平均分
--? 如果平均分在70以上,显示“考试成绩优秀”,并显示前三名学生的考试信息 --? 如果在70以下,显示“考试成绩较差”,并显示后三名学生的考试信息
declare@lastExamdatetime select@lastExam=max(r.ExamDate) fromResultr,Subjects
wherer.SubjectNo=s.SubjectNoands.SubjectName='java' print@lastExam
declare@avgScoredecimal
select@avgScore=AVG(r.StudentResult) fromResultr,Subjects
wherer.SubjectNo=s.SubjectNoands.SubjectName='java'andr.ExamDate=@lastExam
begin end begin end
print'考试成绩差,后三名的成绩为:' selecttop 3 StudentNo,StudentResult fromResultinnerjoinSubject
onResult.SubjectNo=Subject.SubjectNo
whereSubjectName='Java Logic'andExanDate=@data orderbyStudentResult
print'考试成绩优秀,前三名的成绩为:' selecttop 3 StudentNo,StudentResult fromResultinnerjoinSubject
onResult.SubjectNo=Subject.SubjectNo
whereSubjectName='Java Logic'andExanDate=@data orderbyStudentResultdesc
else
print@avgScore
if(@avgScore>70)
begin
print'考试成绩优秀' selecttop 3
s.StudentName,r.StudentResult,CONVERT(char(10),r.ExamDate,20),'java'as考试科目
end begin
print'考试成绩较差' selecttop 3
fromResultr,Students
wherer.StudentNo=s.StudentNo orderbyr.StudentResultdesc
else
s.StudentName,r.StudentResult,CONVERT(char(10),r.ExamDate,20),'java'as考试科目
--? 检查学生“Winforms”课最近一次考试是否有不及格(60分及格)的学生。如有,每人加2分,高于95分的学生不再加分,直至所有学生这次考试成绩均及格。 --? 第一步:统计没通过的人数 --? 第二步:如果有人没通过,加分 --? 第三步:循环判断
declare@lastExam1datetime declare@failCountint declare@subjectidint --课程编号
end
fromResultr,Students
wherer.StudentNo=s.StudentNoandr.ExamDate=@lastExam orderbyr.StudentResult
select@subjectid=SubjectNo fromSubject
whereSubjectNamelike'%java%' --最近一次考试时间找到
select@lastExam1=MAX(r.ExamDate) fromResultr,Subjects
wherer.SubjectNo=s.SubjectNoands.SubjectNo=@subjectid print@lastExam1 while(1=1)
begin end
--不及格人数
select@failCount=count(*) fromResultr
whereSubjectNo=@subjectidandExamDate=@lastExam1andStudentResult<60 --每人加2分,高于95分的学生不再加分,直至所有学生这次考试成绩均及格。 if(@failCount>0)
end break begin
updateResultsetStudentResult+=2
whereSubjectNo=@subjectidandExamDate=@lastExam1andStudentResult<95
else
--查询结果
selects.StudentName,r.StudentResult fromResultr,Students
wherer.StudentNo=s.StudentNoandSubjectNo=@subjectidandExamDate=@lastExam1
-------------------------------CASE-END
--? 采用美国ABCDE五级打分制显示学生Java Logic课最近一次考试成绩 --? A级: 90分以上 --? B级: 80-89分 --? C级: 70-79分
--? D级: 60-69分 --? E级: 60分以下
declare@lastExam2datetime declare@subjectid2int
select@subjectid2=SubjectNo
fromSubjectswhereSubjectNamelike'java'
select@lastExam2=ExamDate
fromResultwhereSubjectNo=@subjectid2
selects.StudentNo,s.StudentName, case
whenr.StudentResult>=90 then'A级' whenr.StudentResult>=80 then'B级' whenr.StudentResult>=70 then'C级' whenr.StudentResult>=60 then'D级' else'E级'
endas'成绩等级' fromResultr,Students
wherer.StudentNo=s.StudentNoandSubjectNo=@subjectid2andExamDate=@lastExam2
--批处理
createtablePunish ( ) go
insertintoPunish
selectStudentNo学号,count(*)不及格次数,''处理意见
StudentNointprimarykey, FailCountintnotnull, Advicenvarchar(10)