Triangle Judgement
Problem
Triangle(x, y, z). Decide whether each row forms a triangle.
Input
t=[(13,15,30),(10,20,15)]Output
[(13,15,30,'No'),(10,20,15,'Yes')]13+15 ≤ 30 fails; 10+15 > 20 passes.
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;
Explanation
Three lengths can form a real triangle only if they satisfy the triangle inequality: the sum of any two sides must be strictly greater than the third. If even one pair fails, the sides can't close into a triangle.
The query checks all three conditions at once with x + y > z AND x + z > y AND y + z > x. A CASE then outputs 'Yes' when all three hold and 'No' otherwise, evaluated row by row.
Checking all three covers every ordering, so it doesn't matter which side happens to be the longest.
Example: (13, 15, 30) fails because 13 + 15 = 28 is not greater than 30, giving 'No'. But (10, 20, 15) passes all three checks, so it's 'Yes'.