【问题标题】:Select query without display选择不显示的查询
【发布时间】:2017-12-29 16:14:47
【问题描述】:

我有这个代码

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】:

    只需选择您想要的。它似乎是:

    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 都是非负数。

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 2020-02-22
    • 2017-12-02
    相关资源
    最近更新 更多