Description
Write a SQL query to determine if three sides can form a valid triangle. Return x, y, z, triangle ('Yes' or 'No').
Table:
triangle| Column | Type |
|---|---|
| x | INT |
| y | INT |
| z | INT |
Examples
Input:
CREATE TABLE triangle (x INT, y INT, z INT); INSERT INTO triangle VALUES (13, 15, 30), (10, 20, 15);Output:
13|15|30|No
10|20|15|YesExplanation:
For (13,15,30): 13+15=28 which is NOT > 30, so it cannot form a triangle. For (10,20,15): all sums exceed the third side (10+20>15, 10+15>20, 20+15>10), so it can form a triangle.
Input:
CREATE TABLE triangle (x INT, y INT, z INT); INSERT INTO triangle VALUES (5, 5, 5), (3, 4, 8);Output:
5|5|5|Yes
3|4|8|NoExplanation:
First triangle (5,5,5) is equilateral - all sides equal and each pair sum exceeds the third (5+5>5). Second triangle (3,4,8) fails because 3+4=7 which is not greater than 8, violating the triangle inequality.
Input:
CREATE TABLE triangle (x INT, y INT, z INT); INSERT INTO triangle VALUES (1, 1, 1), (6, 8, 10);Output:
1|1|1|Yes
6|8|10|YesExplanation:
First triangle (1,1,1) shows the smallest possible valid triangle where all sides are 1. Second triangle (6,8,10) is a right triangle (6²+8²=10²) and satisfies all triangle inequalities: 6+8>10, 6+10>8, and 8+10>6.
Constraints
- •
a + b > c for all combinations