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
|
3370 Discussions
|
Please Login in order to post a comment
in MySQL:
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 AS TriangleType FROM TRIANGLES;
Oracle:
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 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 B=C) then "Equilateral" when (A!=B and B!=C and A!=C) then "Scalene" when (A=B or B=C or A=C) then "Isosceles" end as Triangle_type from Triangles
/* "Not A Triangle" condition should be checked first then other conditions, because if its not a valid triangle then there is no point of checking otherconditions */
For MySQL
MySQL Server:
select Case when A+B <=C or A+C <=B or C+B <= A then 'Not A Triangle' when (A=B and B = C) then 'Equilateral' when (A=B or B = C or C=A) then 'Isosceles' ELSE 'Scalene' END as triangle_type from triangles;