Given a table Triangles that contains the lengths of three sides of triangles, write a SQL query to classify each triangle based on its side lengths.
Triangle Classification Rules:
- Equilateral: All three sides are equal in length
- Isosceles: Exactly two sides are equal in length
- Scalene: All three sides have different lengths
- Not A Triangle: The given side lengths cannot form a valid triangle
Triangle Validity Rule: For three sides A, B, and C to form a triangle, the sum of any two sides must be greater than the third side.
Table Schema
| Column Name | Type | Description |
|---|---|---|
A
PK
|
int | Length of first side |
B
PK
|
int | Length of second side |
C
PK
|
int | Length of third side |
Input & Output
| A | B | C |
|---|---|---|
| 10 | 10 | 10 |
| 13 | 15 | 30 |
| 20 | 21 | 22 |
| A | B | C | triangle_type |
|---|---|---|---|
| 10 | 10 | 10 | Equilateral |
| 13 | 15 | 30 | Not A Triangle |
| 20 | 21 | 22 | Scalene |
First triangle (10,10,10): All sides equal → Equilateral. Second triangle (13,15,30): 13+15=28 < 30, violates triangle inequality → Not A Triangle. Third triangle (20,21,22): All sides different and valid → Scalene.
| A | B | C |
|---|---|---|
| 5 | 5 | 8 |
| 10 | 12 | 10 |
| A | B | C | triangle_type |
|---|---|---|---|
| 5 | 5 | 8 | Isosceles |
| 10 | 12 | 10 | Isosceles |
Both triangles have exactly two sides of equal length: (5,5,8) has A=B, and (10,12,10) has A=C. Both satisfy triangle inequality and are classified as Isosceles.
Constraints
-
1 ≤ A, B, C ≤ 100 - All side lengths are positive integers