0

这是我的代码:

Select 
   cname, 
   case
       WHEN cid < 35 then 'Failed'
       WHEN cid > 35 AND < 50 then 'Below Average'
       WHEN cid > 50 AND < 60 then 'Average'
       WHEN cid > 60 AND < 70 then 'Good'
       WHEN cid > 70 AND < 85 then 'Distinction'
       WHEN cid > 85 then 'Outstanding' 
   end as Report 
from cus

我不知道上面的代码有什么问题。它没有得到正确执行。

它显示了这样的结果。

消息 102,级别 15,状态 1,第 3 行
'<' 附近的语法不正确。

我可以知道我犯了什么错误,以及如何克服它吗?

4

2 回答 2

2

将您的案例更改为

Select cname, case
WHEN cid < 35 then 'Failed'
When cid >35 and cid<50 then 'Below Average'
WHEN cid >50 and cid<60 then 'Average'
WHEN cid >60 and cid<70 then 'Good'
WHEN cid >70 and cid<85 then 'Distinction'
WHEN cid >85 then 'Outstanding' end as Report from cus

您忘记指定cid第二个条件。

另一方面,如果它是 exaclt 50 会发生什么?

您可能希望将其更改为包含/排他的从句。就像是

Select cname, case
WHEN cid <= 35 then 'Failed'
When cid >35 and cid<=50 then 'Below Average'
WHEN cid >50 and cid<=60 then 'Average'
WHEN cid >60 and cid<=70 then 'Good'
WHEN cid >70 and cid<=85 then 'Distinction'
WHEN cid >85 then 'Outstanding' end as Report from cus
于 2014-03-14T05:58:46.363 回答
0

尝试这个

Select 
   cname, 
   case
       WHEN cid < 35 then 'Failed'
       WHEN cid > 35 AND cid  < 50 then 'Below Average'
       WHEN cid > 50 AND cid  < 60 then 'Average'
       WHEN cid > 60 AND cid  < 70 then 'Good'
       WHEN cid > 70 AND cid  < 85 then 'Distinction'
       WHEN cid > 85 then 'Outstanding' 
   end as Report 
from cus
于 2014-03-14T06:13:32.253 回答