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

cid2 番目の条件を指定するのを忘れました。

余談ですが、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 に答える