选择查询而不显示

时间:2017-12-29 16:14:48

标签: sql oracle case

我有这段代码

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;

我只希望它显示字符串equilateralnot a triangle。不显示列的内容。我该怎么做?

1 个答案:

答案 0 :(得分:2)

只需选择您想要的内容即可。看起来似乎是:

select (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;

请注意,我在表达式中替换了标准SQL运算符。由于case的优先级和修复逻辑,这可以是:

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

这假定ABC都是非负面的。