Triangle Judgement
Task: Report for every three line segments whether they can form a triangle.
Table: Triangle
+-------------+------+
| Column Name | Type |
+-------------+------+
| x | INT |
| y | INT |
| z | INT |
+-------------+------+
Input: Triangle table:
+----+----+----+
| x | y | z |
+----+----+----+
| 13 | 15 | 30 |
| 10 | 20 | 15 |
+----+----+----+
Output:
+----+----+----+----------+
| x | y | z | triangle |
+----+----+----+----------+
| 13 | 15 | 30 | No |
| 10 | 20 | 15 | Yes |
+----+----+----+----------+ View Reference Solution & Explanation ▼
This solution uses a `CASE` statement for conditional logic to find the required output.
SELECT x, y, z, CASE WHEN x + y > z AND x + z > y AND y + z > x THEN 'Yes' ELSE 'No' END AS triangle FROM Triangle;