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

admin2021-07-14  43

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

最新回复(0)