选择查询而不显示

问题描述 投票:0回答:1

我有这个代码

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。不显示列的内容。我怎么做?

sql oracle case
1个回答
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都是非负的。

© www.soinside.com 2019 - 2024. All rights reserved.