코딩테스트연습(SQL)
Type of Triangle / HackerRank, SQL, MySQL
LearnerToRunner
2022. 12. 4. 00:37
문제
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.
제출답안(MySQL)
SELECT
CASE WHEN (a+b<=c OR a+c<= b OR b+c<= a) THEN 'Not A Triangle'
WHEN (a=b AND a=c) THEN 'Equilateral'
WHEN (a!=b AND b!=c AND c!=a) THEN 'Scalene'
ELSE 'Isosceles' END
FROM triangles
문제 바로가기(MySQL)
728x90