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

admin2021-05-07  30

问题 设在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’女’
    EISE’其它’
    END
    即可以表示。但如果条件较为复杂或包含判断式等,则用D所表示的方式。
转载请注明原文地址:https://jikaoti.com/ti/Sj37FFFM
0

最新回复(0)