下面是我的代码:
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行
'<'附近语法错误。
我可以知道我犯了什么错误,以及如何克服它吗?
将大小写改为
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
。
作为一个边不,如果正好是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
试试这个
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