Im between cherry

Hackerrank | MySQL | Type of Triangle 본문

데이터분석/practice_query

Hackerrank | MySQL | Type of Triangle

meal 2020. 8. 29. 20:08

Type of Triangle

Problem

 

Type of Triangle | HackerRank

Query a triangle's type based on its side lengths.

www.hackerrank.com

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

  • Equilateral: It's a triangle with  sides of equal length.
  • Isosceles: It's a triangle with  sides of equal length.
  • Scalene: It's a triangle with  sides of differing lengths.
  • Not A Triangle: The given values of A, B, and C don't form a triangle.

 

SELECT CASE
    WHEN A + B > C AND A + C > B AND B + C > A 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
Comments