在oracle sql中使用CASE语句

时间:2017-12-29 09:36:11

标签: sql oracle

我有下表

A   B    C
20  20   23
20  20   20
20  21   22
13  14   30 

命名三角形,如果三角形是等边,等腰,斜角或不是三角形,我需要每次输出。
我使用了以下代码:

select A,B,C,
case
when A = B = C then'Equilateral' 
when A + B < C then "Not A Triangle"
when (A = B and B != C) or (A = C and B != A) or ( B = C and A != B ) then "Isoceles"
else "Scalene"
end,  
from Triangles;

但是我收到了这个错误:

when A = B = C then'Equilateral' 
* 
ERROR at line 3: 
ORA-00905: missing keyword 

1 个答案:

答案 0 :(得分:1)

这是因为您必须将这些内容分别设置为A = BB = C并删除,之后的end(因为您不再有列)< / p>

select A,B,C,
       case
         when A = B and B = C then'Equilateral' 
         when A + B < C then 'Not A Triangle'
         when (A = B and B != C) or (A = C and B != A) or ( B = C and A != B ) then 'Isoceles'
         else 'Scalene'
       end
from Triangles;