//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
第三章SQL编程--经典案例和上级题
最新推荐文章于 2024-05-23 20:49:26 发布
本文通过SQL展示了对2013年8月9日OOP考试成绩的详细分析,包括平均分计算、成绩评价及不及格学生加分策略。同时,还提供了SQL上机题和面试题的解决方案,涉及条件判断、循环、聚合函数和数据更新操作。
摘要由CSDN通过智能技术生成