CASE-END练习答案
数据库:USE stuDB
代码:
GO
SELECT
考号 = ExamNo,
学号 = stuNo,
笔试 = writtenExam,
机试 = labExam,
平均分 = (writtenExam + labExam) / 2,
等级 = CASE
WHEN (writtenExam + labExam) / 2 >= 90 THEN '优秀'
WHEN (writtenExam + labExam) / 2 >= 75 THEN '良好'
WHEN (writtenExam + labExam) / 2 >= 60 THEN '合格'
ELSE '不合格'
END
FROM student_scores;
说明:该查询从student_scores
表中选择学生的考号、学号、笔试成绩、机试成绩、平均分,并依据平均分划分等级。条件通过CASE
语句定义,以确保评分的分类简明且有逻辑。