https://www.hackerrank.com/challenges/what-type-of-triangle/problem
Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table:
- Equilateral: It's a triangle with 3 sides of equal length.
- Isosceles: It's a triangle with 2 sides of equal length.
- Scalene: It's a triangle with 3 sides of differing lengths.
- Not A Triangle: The given values of A, B, and C don't form a triangle.
Input Format
The TRIANGLES table is described as follows:
Each row in the table denotes the lengths of each of a triangle's three sides.
Sample Input
Sample Output
Isosceles
Equilateral
Scalene
Not A Triangle
SELECT IF(A+B>C AND A+C>B AND B+C>A, IF(A=B AND B=C, 'Equilateral', IF(A=B OR B=C OR A=C, 'Isosceles', 'Scalene')), 'Not A Triangle')
FROM TRIANGLES;
‘IF(condition, A, B)’
TRUE 면 A 아니면 B
'Algorithm > SQL' 카테고리의 다른 글
[SQL][HackerRank] Revising Aggregations - The Count Function (0) | 2020.06.11 |
---|---|
[SQL][HackerRank] The PADS (0) | 2020.06.11 |
[SQL][HackerRank] Placements (0) | 2020.06.11 |
[SQL][HackerRank] Contest Leaderboard (0) | 2020.06.11 |
[SQL][HackerRank] Weather Observation Station 20 (0) | 2020.06.10 |