Algorithm


Problem Name: Sql - Type of Triangle

Problem Link: https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true

In this HackerRank Functions in SQL problem solution,

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.

nput 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

 

Code Examples

#1 Code Example with SQL

Code - SQL


SELECT CASE 
WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle' 
WHEN A = B AND B = C THEN 'Equilateral' 
WHEN A = B OR B = C OR A = C THEN 'Isosceles' 
ELSE 'Scalene' 
END 
FROM TRIANGLES;
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Previous
[Solved] Employee Salaries in SQL solution in Hackerrank
Next
[Solved] Revising the Select Query I in SQL solution in Hackerrank