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
|
3496 Discussions
|
Please Login in order to post a comment
SELECT CASE WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle'
END AS triangle_type 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 OR B = C OR C = A THEN 'Isosceles' ELSE 'Scalene' END AS TriangleType FROM TRIANGLES; **
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 Triangle_Type FROM TRIANGLES;
Many of you are so close! Remeber, the order of your cases is important!
Hint 1: Its easiest if you check to see if it a triangle or not a triangle first.
Hint 2: SQL looks for the first TRUE Case. If not written in the correct order, it is possible for a triangle with 3 equal sides to be marked as an "Isosceles".
Don't forget about "ELSE". (Hopefully this doens't make it more confusing)
:)
what is wrong with this query to check if not a triangle: SELECT CASE WHEN A=B AND B=C AND C=A THEN 'Equilateral' WHEN (A=B) OR (B=C) OR (C=A) THEN 'Isosceles' WHEN ((A+B)<=C)OR((B+C)<=A)OR((C+B)<=A) THEN 'Not A Triangle' WHEN A<>B AND B<>C AND C<>A THEN 'Scalene' END FROM TRIANGLES