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
|
3087 Discussions
|
Please Login in order to post a comment
SELECT CASE WHEN A + B <= C OR B+C <= A OR A+C <= B THEN "Not A Triangle" WHEN A=B AND B=C THEN "Equilateral" WHEN A=B OR C=A OR B=C THEN "Isosceles" ELSE "Scalene" END FROM TRIANGLES
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.
My Solution: SELECT case when A+B<=C OR B+C<=A OR C+A<=B THEN 'Not A Triangle' WHEN (A=B AND B<>C) OR (B=C AND C<>A) OR (A=C AND C<>B) THEN 'Isosceles' WHEN A=B AND B=C THEN 'Equilateral' ELSE 'Scalene' END FROM TRIANGLES;
Check this out Guys
this is not working
select case when ((A+B)<=C) OR ((A+C)<=B) OR ((B+C)<=A) THEN 'NOT A TRIANGLE' when A=B AND B=C AND A=C THEN 'EQUILATERAL' WHEN ((A=B and B<>C) OR (B=C AND C<>A )OR (A=C AND C<>B )) and (((A+B)>C) OR ((A+C)>B) OR ((B+C)>A)) THEN 'ISOSCELES'
when A<>B AND B<>C AND A<>C and (((A+B)>C) OR ((A+C)>B) OR ((B+C)>A)) THEN 'SCALENE' END from triangles;