Type of triangle problem of hackerrank SQl Advance select

Viewed 23

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.

Can someone plz point out what is wrong here :

select if(a=b=c,'Equilateral', 
      (select if(a=b or b=c or c=a,'Isosceles', select if( a+b Triangle','Scalene')))) 
       from triangles;
1 Answers

Just do a select case statement, this is a complete working solution:

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;
Related