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.Input FormatThe TRIANGLES table is described as follows:
Question
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.Input FormatThe TRIANGLES table is described as follows:
Solution
Here is a SQL query that will identify the type of each record in the TRIANGLES table using its three side lengths:
SELECT CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene'
END
ELSE 'Not A Triangle'
END
FROM TRIANGLES;
This query first checks if the given values form a triangle using the triangle inequality theorem (the sum of the lengths of any two sides of a triangle must be greater than the length of the third side). If they do form a triangle, it then checks if all sides are equal (equilateral), two sides are equal (isosceles), or all sides are different (scalene). If the values do not form a triangle, it outputs 'Not A Triangle'.
Similar Questions
Get the lengths of three sides of a triangle. Check whether the triangle can be formed or not. If possible then classify the triangle as equilateral, isosceles or scalene. If unable to form the triangle (the sum of the lengths of any two sides of a triangle must be greater than the length of the third side) print error. An equilateral triangle is a type of triangle that has all three sides of equal length.An isosceles triangle is a type of triangle that has at least two sides of equal length.A scalene triangle is a type of triangle that has all three sides of different lengths.Testcases:Input:444Output: Equilateral triangleInput:5710Output: Scalene triangleInput:249Output: ErrorInput:575Output: Isosceles triangle
A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. However, this assignment is very heavy because there are hundreds of records to calculate.Could you help Tim by writing a query to judge whether these three sides can form a triangle, assuming table triangle holds the length of the three sides x, y and z.xyz131530102015For the sample data above, your query should return the follow result:xyztriangle131530No102015yesOptionsselect case when x + y > z and x + z > y and y + z > x then 'Yes' else 'No' end as trianglefrom triangle ;select x, y, z, case when x + y > z and x + z > y and y + z > x then 'Yes' else 'No' end as trianglefrom triangle ;select x, y, z, when x + y > z and x + z > y and y + z > x then 'Yes' else 'No' end as trianglefrom triangle ;select x, y, z, case when x + y > z and x + z > y and y + z > x then 'Yes' end as trianglefrom triangle ;
The triangle fits which of the following classifications?Picture is not drawn to scale.I. RightII. ScaleneIII. AcuteIV. Equilateral A. I and III B. II and III C. II and IV D. II only
Which of the following lists of numbers could be the side lengths, in inches, of a triangle?
Classify the following triangle. Check all that apply.A.IsoscelesB.AcuteC.ScaleneD.EquilateralE.RightF.ObtuseSUBMITarrow_backPREVIOUS
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.