We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

- Prepare
- SQL
- Advanced Select
- Type of Triangle
- Discussions

# Type of Triangle

# Type of Triangle

#### Sort by

recency

#### |

#### 2969 Discussions

#### |

Please Login in order to post a comment

SELECT CASE WHEN A=B AND B=C THEN 'Equilateral' WHEN (A=B OR A=C OR B=C) AND A+B!=C THEN 'Isosceles' WHEN A!=B AND B!=C AND (A+B>=C) THEN 'Scalene' WHEN A+B<=C THEN 'Not A Triangle' END FROM TRIANGLES ;

MYSQL answer:

If your code isn't working and you don't know why, it might be because you're not using <= for your Not A Triangle check.

If A + B = C, it's not a triangle. The problem description didn't make that as clear as it could have.

MS SQL SERVER

SELECT CASE WHEN A >= (B + C) OR B >= (A + C) OR C >= (A + B) THEN 'Not A Triangle' WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR A = C OR B = C THEN 'Isosceles' ELSE 'Scalene' END AS TriangleType FROM TRIANGLES

Select case when A+B<=C OR B+C<=A OR C+A<=B THEN "Not A Triangle" when A=B AND A=C THEN 'Equilateral' when A=B OR B=C OR C=A THEN 'Isosceles' else 'Scalene' end from triangles;