Triangle Judgement

Write an SQL query to report for every three line segments whether they can form a triangle.

Return the result table in any order.

table name: Triangle

Solution:

select x,y,z, case when x+y>z and y+z>x and z+x>y then 'Yes' else 'No' end as triangle from triangle

Output:


SQL Script:

Create table Triangle (x int, y int, z int)
insert into Triangle (x, y, z) values ('13', '15', '30')
insert into Triangle (x, y, z) values ('10', '20', '15')

Comments (0)