如何在mysql中使用嵌套大小写查找三角形的类型(给出了三条边的长度)?

bkkx9g8r  于 2021-07-24  发布在  Java
关注(0)|答案(2)|浏览(309)

这个问题在这里已经有答案了

mysql中的三角形类型(19个答案)
10个月前关门了。

在这个mysql查询中wrobg是什么?它显示语法错误。

SELECT
CASE
    WHEN A = B
        CASE
            WHEN A = C THEN 'Equilateral'
            WHEN C < A + B THEN 'Isosceles'
            ELSE 'Not A Triangle'
        END
    WHEN B = C
        CASE
            WHEN A < B + C THEN 'Isosceles'
            ELSE 'Not A Triangle'
        END
    WHEN A + B > C AND A + C > B AND B + C > A THEN 'Scalene'
    ELSE 'Not A Triangle'
END
FROM TRIANGLES;
yzuktlbb

yzuktlbb1#

为此,您还必须添加一个

SELECT
CASE
    WHEN A = B
    THEN
        CASE
            WHEN A = C THEN 'Equilateral'
            WHEN C < A + B THEN 'Isosceles'
            ELSE 'Not A Triangle'
        END
    WHEN B = C
    THEN
        CASE
            WHEN A < B + C THEN 'Isosceles'
            ELSE 'Not A Triangle'
        END
    WHEN A + B > C AND A + C > B AND B + C > A THEN 'Scalene'
    ELSE 'Not A Triangle'
END
FROM TRIANGLES;
mctunoxg

mctunoxg2#

没有必要筑巢 case 表达:

SELECT (CASE WHEN A = B AND A = C THEN 'Equilateral'
             WHEN A = B AND C < A + B THEN 'Isosceles'
             WHEN A = B THEN 'Not A Triangle'
             WHEN B = C AND A < B + C THEN 'Isosceles'
             WHEN B = C THEN 'Not A Triangle'
             WHEN A + B > C AND A + C > B AND B + C > A THEN 'Scalene'
             ELSE 'Not A Triangle'
        END) as type
FROM TRIANGLES;

相关问题