반응형
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.
select
case
when a + b <= c or a + c <= b or b + c <= a then 'Not A Triangle'
when a = b and b = c and a = c then 'Equilateral'
when a = b or b = c or a = c then 'Isosceles'
else 'Scalene'
end as triangle_type
from triangles;
- 삼각형 조건: 세 변의 합 조건을 먼저 확인해야 하므로 가장 앞에 둡니다.
- (삼각형이 아니면 이후 분류는 무의미)
- A = B AND B = C: 세 변이 모두 같으면 Equilateral
- A = B OR B = C OR A = C: 두 변만 같으면 Isosceles
- 나머지는 Scalene
반응형
'Computer Science > SQL' 카테고리의 다른 글
SQL | HackerRank 정규표현식으로 도시 찾기 – DISTINCT와 REGEXP 활용 (0) | 2025.06.13 |
---|---|
SQL | HackerRank 가장 짧고 긴 도시 이름 찾기 – 문자열 길이 기반 SQL 정렬과 조건 추출 (2) | 2025.06.12 |
SQL | LeetCode 1327. 특정 월 기준 주문량 분석하기 (0) | 2025.06.10 |
SQL | LeetCode 1484. 날짜별로 팔린 제품들 정리하기 (GROUP BY + 정렬 + 문자열 조합) (3) | 2025.06.09 |
SQL | LeetCode 176. 두 번째 최대값 구하기 (DENSE_RANK) (0) | 2025.06.08 |