//if-lse经典案例
--统计并显示2013-08-09 的oop考试平均分
--如果平均分在70以上,显示“考试成绩优秀”,并显示前三名学生的考试信息
--如果在70分以下,显示“考试成绩较差”,并显示后三名学生的考试信息
--01.定义一个变量,保存平均分
select * from Result
--查编号
declare @subid int
select @subid=SubjectId from Subject
where subjectname='oop'
--查询平均分
declare @avg int
select @avg=avg(Studentresult)from result
where examdate>='2013-08-09' and examdate<'2013-08-10' and SubjectId=@subid
--前三名
if(@avg>=70)
begin
print '成绩优秀'
select top 3 * from Result where examdate>='2013-08-09' and ExamDate<'2013-08-10' and SubjectId=@subid
order by StudentResult desc
end
if(@avg<70)
begin
print '考试成绩较差'
select top 3 * from Result where examdate>='2013-08-09' and ExamDate<'2013-08-10' and SubjectId=@subid
order by StudentResult
end
//while经典案例
--科目名为oop的id
declare @subid int
select @subid=SubjectId from subject
where SubjectName='oop'
print @subid
--科目名为oop的最近考试时间
declare @maxdate datetime
select @