Type of Triangle in MYSQL

前端 未结 18 2159
执念已碎
执念已碎 2020-12-09 11:48

Problem statement:

Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the followin

18条回答
  •  醉梦人生
    2020-12-09 12:32

    SELECT  CASE
        WHEN A+B>C AND B+C>A AND A+C>B THEN
            CASE 
                WHEN A=B AND B=C THEN 'Equilateral'
                WHEN A=B or A=C OR B=C THEN 'Isosceles'
                ELSE 'Scalene'
            END
        ELSE 'Not A Triangle'
    END
    FROM TRIANGLES 
    
    • Step 1: First we select case to check if given input is a triangle or not

    • Step 2: If it is a triangle then check for its type. So first case if all sides are the same, then the triangle type is 'Equilateral', then second case if any two sides are the same then the triangle type is 'Isosceles', otherwise the triangle type is 'Scalene'.

提交回复
热议问题