You have a table Triangle containing the lengths of three line segments.
Write an SQL query to report for every three line segments whether they can form a triangle.
A triangle can be formed if the sum of any two sides is greater than the third side. This must be true for all three combinations:
x + y > zx + z > yy + z > x
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
x
PK
|
int | Length of first line segment |
y
PK
|
int | Length of second line segment |
z
PK
|
int | Length of third line segment |
Input & Output
| x | y | z |
|---|---|---|
| 13 | 15 | 30 |
| 10 | 20 | 15 |
| x | y | z | triangle |
|---|---|---|---|
| 13 | 15 | 30 | No |
| 10 | 20 | 15 | Yes |
For the first row: 13 + 15 = 28, which is not greater than 30, so it cannot form a triangle.
For the second row: 10 + 20 = 30 > 15, 10 + 15 = 25 > 20, and 20 + 15 = 35 > 10. All conditions are satisfied, so it can form a triangle.
| x | y | z |
|---|---|---|
| 1 | 1 | 1 |
| 1 | 2 | 3 |
| x | y | z | triangle |
|---|---|---|---|
| 1 | 1 | 1 | Yes |
| 1 | 2 | 3 | No |
For equilateral triangle (1,1,1): All sides equal, so 1+1=2 > 1 for all combinations - forms a triangle.
For degenerate case (1,2,3): 1+2=3 which equals the third side, not greater than it - cannot form a triangle.
Constraints
-
1 ≤ x, y, z ≤ 100 - All side lengths are positive integers