Triangle Judgement Problem


Description

LeetCode Problem 610.

A pupil Tim gets homework to identify whether three line segments could possibly form a triangle.

However, this assignment is very heavy because there are hundreds of records to calculate.

Could you help Tim by writing a query to judge whether these three sides can form a triangle, assuming table triangle holds the length of the three sides x, y and z.

1
2
3
4
| x  | y  | z  |
|----|----|----|
| 13 | 15 | 30 |
| 10 | 20 | 15 |

For the sample data above, your query should return the follow result:

1
2
3
4
| x  | y  | z  | triangle |
|----|----|----|----------|
| 13 | 15 | 30 | No       |
| 10 | 20 | 15 | Yes      |


MySQL Solution

1
2
3
select *, 
    if(x+y>z and x+z>y and y+z>x, 'Yes', 'No') as triangle
from triangle




Related Posts

Students Report By Geography Problem

LeetCode 618. A U.S graduate school has students from Asia,...

Average Salary: Departments VS Company Problem

LeetCode 615. Given two tables as below, write a query...

Second Degree Follower Problem

LeetCode 614. Please write a sql query to get the...

Shortest Distance In A Plane Problem

LeetCode 612. Write a query to find the shortest distance...

Triangle Judgement Problem

LeetCode 610. A pupil Tim gets homework to identify whether...

Shortest Distance Problem

LeetCode 613. Write a query to find the shortest distance...