Type of Triangle in MYSQL

前端 未结 18 2476
执念已碎
执念已碎 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:24

    /* THE BELOW CODE WILL CHECK ALL THE POSSIBLE CASES OF A TRIANGLE, THIS CODE WILL WORK 100% */

    select case
    when A+B<=C OR A+C<=B OR C+B<=A THEN "Not A Triangle"
    when (A<>B AND A+B>C) AND (B<>C AND B+C>A) AND (A<>C AND A+C>B) THEN 
    "Scalene"
    when (A=B AND B<>C AND A+B>C) OR (B=C AND B<>A AND B+C>A) OR (A=C AND C<>B 
    AND A+C>B) THEN "Isosceles"
    when A=B AND B=C THEN "Equilateral"
    end as triangle
    from TRIANGLES;
    

提交回复
热议问题