-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTriangle Judgement 8-10-22
More file actions
33 lines (21 loc) · 946 Bytes
/
Triangle Judgement 8-10-22
File metadata and controls
33 lines (21 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
link ----- https://www.codingninjas.com/codestudio/problems/triangle-judgement_2111954?topList=top-100-sql-problems
Problem Statement
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.
| x | y | z |
|----|----|----|
| 13 | 15 | 30 |
| 10 | 20 | 15 |
For the sample data above, your query should return the follow result:
| x | y | z | triangle |
|----|----|----|----------|
| 13 | 15 | 30 | No |
| 10 | 20 | 15 | Yes |
--------------------- solution ------------------------
select *,
case
when X+Y>Z and X+Z>Y and Z+Y>X then 'Yes'
else 'No'
end as triangle
from TRIANGLE