forked from nathan-abela/HackerRank-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01 - Type of Triangle.sql
More file actions
32 lines (27 loc) · 960 Bytes
/
01 - Type of Triangle.sql
File metadata and controls
32 lines (27 loc) · 960 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
-- ========================
-- Information
-- ========================
-- Direct Link: https://www.hackerrank.com/challenges/revising-the-select-query/problem
-- Difficulty: Easy
-- Max Score: 20
-- DBMS: mySQL
-- ========================
-- Solution
-- ========================
SELECT
CASE
WHEN A + B <= C OR A + C <= B OR B + C <= A
THEN 'Not A Triangle'
WHEN A = B AND A = C AND B = C
THEN 'Equilateral'
WHEN A = B OR A = C OR B = C
THEN 'Isosceles'
ELSE 'Scalene'
END
FROM TRIANGLES;
-- ========================
-- Explanation
-- ========================
-- 'CASE' goes through conditions and return a value when the first condition is met (like an IF-ELSE statement). So, once a condition is true, it will stop reading and return the result.
-- If no conditions are true, it will return the value in the ELSE clause.
-- If there is no ELSE part and no conditions are true, it returns NULL.