Skip to content

Instantly share code, notes, and snippets.

@HaiBV
Last active October 26, 2019 09:22
Show Gist options
  • Save HaiBV/23bb9df710db280110d4643f50be402b to your computer and use it in GitHub Desktop.
Save HaiBV/23bb9df710db280110d4643f50be402b to your computer and use it in GitHub Desktop.
typeOfTriangle.sql
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;
@HaiBV
Copy link
Author

HaiBV commented Oct 26, 2019

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 Format

The TRIANGLES table is described as follows:
CREATE TABLE TRIANGLES ( A INT(6), B INT(6), C INT(6) )

Each row in the table denotes the lengths of each of a triangle's three sides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment