设在SQL Server 2008某数据库中有表SC(Sno,Cno,Grade),其中Grade列的类型为int。若在查询成绩时,希望将成绩按“优”、“良”、“中”、“及格”和“不及格”形式显示,则下列Case函数中正确的是( )。

admin2021-06-28  31

问题 设在SQL Server 2008某数据库中有表SC(Sno,Cno,Grade),其中Grade列的类型为int。若在查询成绩时,希望将成绩按“优”、“良”、“中”、“及格”和“不及格”形式显示,则下列Case函数中正确的是(    )。

选项 A、Case Grade
When Grade between 90 and 100 THEN Grade=ˊ优ˊ
When Grade between 80 and 89 THEN Grade=ˊ良ˊ
When Grade between 70 and 79 THEN Grade=ˊ中ˊ
When Grade between 60 and 69 THEN Grade=ˊ及格ˊ
Else Grade=ˊ不及格ˊ
End
B、Case Grade
When Grade between 90 and 100 THENˊ优ˊ
When Grade between 80 and 89 THENˊ良ˊ
When Grade between 70 and 79 THENˊ中ˊ
When Grade between 60 and 69 THENˊ及格ˊ
Elseˊ不及格ˊ
End
C、Case  
When Grade between 90 and 100 THEN Grade=ˊ优ˊ
When Grade between 80 and 89 THEN Grade=ˊ良ˊ
When Grade between 70 and 79 THEN Grade=ˊ中ˊ
When Grade between 60 and 69 THEN Grade=ˊ及格ˊ
Else Grade=ˊ不及格ˊ
End
D、Case
When Grade between 90 and 100 THENˊ优ˊ
When Grade between 80 and 89 THENˊ良ˊ
When Grade between 70 and 79 THENˊ中ˊ
When Grade between 60 and 69 THENˊ及格ˊ
Elseˊ不及格ˊ
End

答案D

解析 此题考察了SQL中CASE WHEN语句的用法。如果是简单的赋值查询,比如数据库表示性别:1表示男,2表示女。则用
CASE sex
Whenˊ1ˊTHENˊ男ˊ
Whenˊ2ˊTHENˊ女ˊ
ELSEˊ其它ˊ
END
即可以表示。但如果条件较为复杂或包含判断式等,则用D所表示的方式。
转载请注明原文地址:https://jikaoti.com/ti/UF37FFFM
0

最新回复(0)