HackerRank/SQL

[hackerrank] type of triangle

예쁜꽃이피었으면 2022. 8. 17. 15:37

[hackerrank] Prepare > SQL > Advanced Select > type of triangle

 

[문제]

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  sides of equal length.
  • Isosceles: It's a triangle with  sides of equal length.
  • Scalene: It's a triangle with  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

Explanation

Values in the tuple  form an Isosceles triangle, because .
Values in the tuple  form an Equilateral triangle, because . Values in the tuple  form a Scalene triangle, because .
Values in the tuple  cannot form a triangle because the combined value of sides  and  is not larger than that of side .

 

[MYSQL]

 

 

[ORCALE]

-- select
--     case 
--        when A+B < C or B+C < A or A+C < B then 'Not A Triangle'
--        when A=B and B=C and A=C then 'Equilateral'
--        when A=B or B=C or A=C then 'Isosceles'
--        when A!=B and B!=C and A!=C then 'Scalene' 
--      end 
-- from triangles;

select
    case 
       when A+B <= C or B+C <= A or A+C <= B then 'Not A Triangle'
       when A=B and B=C and A=C then 'Equilateral'
       when A=B or B=C or A=C then 'Isosceles'
       when A!=B and B!=C and A!=C then 'Scalene' 
     end 
from triangles;

 

 

 

반응형

'HackerRank > SQL' 카테고리의 다른 글

[hackerrank] Binary Tree Nodes  (0) 2022.08.18
[hackerrank] The PADS  (0) 2022.08.17
[hackerrank] Binary Tree Nodes  (0) 2022.08.09
[hackerrank] Employee Salaries  (0) 2022.08.09
[hackerrank] Higher Than 75 Marks  (0) 2022.08.09