Report for every three line segments whether they can form a triangle.
Return the result table in any order.
Hints
Hint#1
Review the Triangle Inequality Theorem
Hint#2
Use CASE Statement
Explanation
Triangle inequality
The triangle inequality
states that for any triangle, the sum of the lengths of any two sides must be greater than the length of the remaining side.
To report the status for every three line segments we can use
CASE Statement
A triangle is considered valid if the sum of any two sides is greater than the third side. Conversely
, if the sum of any two sides is less than or equal to the remaining side, it does not form a valid triangle
.
SQL Solution
SELECT * ,
(
CASE
WHEN x+y<=z THEN 'No'
WHEN x+z<=y THEN 'No'
WHEN z+y<=x THEN 'No'
ELSE 'Yes'
END
) AS triangle
FROM Triangle