Practice > SQL > Advanced Select > Type of Triangle

Problem

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.문제링크

Answer

SELECT CASE WHEN A=B and B=C THEN 'Equilateral' -- WHEN절에서는 순서가 중요함. 이미 첫 번째 기준을 충족시키면 그 다음 WHEN 절에서는 포함되지 않음.
            WHEN A+B <= C OR B+C <= A OR C+A <= B THEN 'Not A Triangle'
            WHEN A=B OR B=C OR C=A THEN 'Isosceles'
            ELSE 'Scalene' END
FROM Triangles

0개의 댓글