320x100
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.
Input Format
The TRIANGLES table is described as follows:

Each row in the table denotes the lengths of each of a triangle's three sides.
Sample Input

Sample Output
Isosceles
Equilateral
Scalene
Not A Triangle
📝 코드
SELECT
CASE
WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle'
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene'
END AS TRIANGLE_TYPE
FROM TRIANGLES;
- CASE WHEN 구문 사용
- 첫 번째 조건 : 삼각형이 아예 안되는 경우
- 두 번째 조건 : 정삼각형이 되는 경우
- 세 번째 조건 : 이등변 삼각형이 되는 경우
- 앞서 정삼각형을 미리 걸렀기 때문에 두 변만 같은 경우들만 남아서 판별하게 됨
- 그 외 조건이라면 세 변이 모두 다른 경우
728x90
'SQL > 코딩테스트 연습' 카테고리의 다른 글
| [HackerRank] Revising the Select Query II (0) | 2026.08.19 |
|---|---|
| [프로그래머스] 부모의 형질을 모두 가지는 대장균 찾기 (MYSQL) (0) | 2025.01.14 |
| [프로그래머스] Python 개발자 찾기 (MYSQL) (0) | 2024.03.18 |
| [프로그래머스] 3월에 태어난 여성 회원 목록 출력하기 (MYSQL) (2) | 2023.12.05 |
| [프로그래머스] 재구매가 일어난 상품과 회원 리스트 구하기 (MYSQL) (1) | 2023.10.11 |