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.

Checking for the 'Not A Triangle' case should use <= as comparator, even though it is stated in the description that A+B should be strictly less than C.

You are right. I finally solved it but issue with the problem statement is what they say in problem is correct 'triangle inequality' whereas what they are asking for is incorrect. Equality exists for triangle with area zero. So still it is a triangle but zero area (Can be argued otherwise also) but problem statement is wrong.

Would like to correct my statement that triangle with area=0 is still a triangle is incorrect.

You are so right too. Brilliant thought.
I also realized that Zero area is only true for the equality condition (Ex. A+B=C) but not for the less than case (A+B

I would disagree as triangle is defined by 3 points on the plane that are not on the same line. Your area "zero" triagle is not a triagle as all 3 point are in line which violates definition of the triangle.

SELECT CASE
WHEN A + B > C THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle'
END
FROM TRIANGLES;

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' WHEN A != B OR B != C OR A != C THEN 'Scalene' END
ELSE 'Not A Triangle' END FROM TRIANGLES;

YOU HAVE TO CHECK FOR ALL COMBINATIONS OF THE CONDITION

select
case
when A+B > C AND A=B AND B=C AND A=C
then 'Equilateral'
when A+B > C AND A=B OR B=C OR A=C
then 'Isosceles'
when A+B > C AND A!=B
then 'Scalene'
else
'Not A Triangle'
End
from TRIANGLES

if "Case1: A + B > C AND A+C>B AND B+C>A" is true then only after that you have to verify "case2: A != B OR B != C OR A != C" which kind of triangle it is. If it is not a valid triangle, case1 will be false and you don't have to worry about the rest cases.

when you use "WHEN A != B OR B != C OR A != C THEN 'Scalene'" why do you use "OR"? shouldn't it be "AND" because ALL 3 sides are not equal? so it will be "WHEN A != B AND B != C THEN 'Scalene'".

Yes you are right AND should be used instead of OR, but even if you use OR then the test case is been submitted..., how is this possible, or there is a fault in the question?

You could also not write the last condition before 'Not A Triangle' to simplify the Query:

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;

If A = B, it doesn't say anything about C (it is not sure than the triangle is ISOSCELES; in fact, it could be EQUILATERAL if A = C).
Here's my version of the script:
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 AND A !=C OR B = C AND B!=A OR A = C AND A!=B THEN 'Isosceles'
ELSE 'Scalene'
END ELSE 'Not A Triangle'
END FROM TRIANGLES;

It's not necessary because in that case, if A = B AND B = C, which is the first case, then it's an equilateral triangle. That's why I put that case as the first one so it won't get to the isosceles triangle case.

You don't need to have multiple CASE statements next to each other or nested CASEs. If you check the conditions in the right order, only one CASE statement with multiple WHENs will do the job:

Hi, could anyone please point out the mistake in my query wriiten below. I am not able to figure out why it says wrong answer!

select case when A+B <=C OR B+C <=A OR C+A <=B then 'not a triangle'
when A=B and B=C and C=A then 'Equilateral triangle'
when A=B or B=C or C=A then 'Isosceles triangle'
else 'Scalene triangle'
end
from TRIANGLES;

The sql query conditions are correct.The statements in the then of sql case should be modified.Change 'Equilateral triangle' to 'Equilateral' and do other changes as below.

select
case
when A+B <=C OR B+C <=A OR C+A <=B then 'Not A Triangle'
when A=B and B=C and C=A then 'Equilateral'
when A=B or B=C or C=A then 'Isosceles'
else 'Scalene'
end
from TRIANGLES;

end is the ending of case statement started at the start of query and from triangle is the part of 'select-from-where' clause in which where is replaced by triangles which is the name of our table/relation in which three sides of triangles are stored.

select case when a+b<=c and b+c<=a and a+c<=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
from triangles

i wrote this code but then why is it showing error for 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 A=C OR B=C THEN 'Isosceles'
ELSE 'Scalene'
END
FROM TRIANGLES;

Hi, Could you please tell me what's the difference between your code and the code below?

SELECT CASE WHEN A + B <= C OR B + C <= A OR C + A <= B THEN 'Not a Triangle'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A = B AND B = C And C = A THEN 'Equilateral'
ELSE 'Scalene'
END
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 A = C OR B = C
then 'Isosceles'
else 'Scalene'

end
FROM Triangles

Edit: Found out it was because the 'a' in 'Not a Triangle' wasn't capitalized. That's more nit-picky than the sql language itself!

I have the exact same thing, good job. Only difference is that I would get an error if I didn't run parenthesis in the conditions like (a+b) <= c. Adding paretheses gave me the right answer....

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 and A!=C and B!=C then 'Scalene'
else 'Isosceles'
end
from TRIANGLES

I came up with nearly the same exact code. However I am receiving errors. I am getting "isoceles" returned instead of "Not a triangle" for one of the test cases.

SELECT
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR A = C OR B = C THEN 'Isosceles'
WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle'
ELSE 'Scalene'
END
FROM TRIANGLES;

Hi Antoniro, I wrote exact the same answer as yours. And I compared the each result in my output with the expected one. Everything is correct but my answer is wrong. The only difference is I have a 16th line which is an empty line in my output. Do you have any idea for this?

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'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle'
END FROM TRIANGLES;

Here, there are two case statements are available, inside CASE doesn't have any else statement. First END is for inside CASE and second END is for outside case.

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

Hi, I don't understand the last bit, it has two END statements. I'm not familiar yet with CASE. Could you please elaborate your thought process here? Thank you!

if sum of any two edges is greater then third edge, we can say it forms a triangle. So there is no need to check B+C>A , A+C>B. Because If A+B>C, it is enough to say they are going to form a triangle.

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'
WHEN A != B and B != C and A != C THEN 'Scalene'
END
ELSE 'Not A Triangle'
END FROM TRIANGLES;

Small suggestion:- For Scalene triangle, no two sides must simultaneously be equal. So, A != B and B != C and A != C might be the complete condition.

SELECT * FROM (
SELECT (CASE
WHEN (A + B <= C) OR (B + C <= A) OR (C + A <= B) THEN 'Not A Triangle'
WHEN (A = B AND B = C AND C = A) THEN 'Equilateral'
WHEN (A = B AND C <> A) OR (A <> B AND B = C ) OR (A = C AND B <> C ) THEN 'Isosceles'
WHEN (A <> B AND B <> C AND C <> A) THEN 'Scalene'
END ) AS TRIANGLE_TYPE
FROM TRIANGLES
)Z;

SELECT CASE WHEN A+B>C THEN CASE WHEN A=B AND B=C Then 'Equilateral' When A=B OR A=C OR B=C THEN 'Isosceles' When A!=B OR B!=C OR C!=A Then 'Scalene' END ELSE 'Not a Triangle' END FROM Triangles;

I wrote this, compared the answer but the compiler claims a fault in it.

SELECT CASE
WHEN ((A + C > B) and (A + B >C) and (C + B >A)) THEN CASE WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR B = C OR A = C THEN 'Isosceles' WHEN A != B OR B != C OR A != C THEN 'Scalene' END
ELSE 'Not A Triangle' END FROM TRIANGLES;

It's assumed that anyone attempting this challenge understands basic Geometry. Any rules will be stated in the Problem Statement at the top of the page. The Explanation section is not stating a rule, it's stating an inequality relevant to the respective A, B, and C values for that Sample Case. The reason why those values do not form a triangle is because 27 is a number that is less than 30. There is a difference between the two numbers. If A and B added up to 30, then the Explanation would say that A + B = C because that would be the immediate reason causing it to not be a triangle.

And yet they are stated like rules in the description... I too was stuck as were all these other people. Perhaps you could be a little less stubborn and fix a clearly misleading description.

I've come here to learn/revise sql, not learn/revise geometry. I think it's odd that the rules at the top cover the basic triangle types that most of us would remember from school, but not the triangle inequality stuff that fewer of us would recall, yet which is only alluded to by example. I didn't know about the latter at all (or had clean forgotten) and just added an 'else' for it.

The case A + B = C corresponds to a Triangle of zero area (zero angles). The technical definition will sometimes allow this, but this problem does not. So, based on the result, the problem is actually stated correctly. The problem is we don't know which axioms she is using.

select
if((A + B > C),if(( A=B and B=C),'Equilateral', if(( A=B or A=C or B=C),'Isosceles',if((A!=B and B!=C),'Scalene','Not A Triangle'))),'Not A Triangle')
as types from TRIANGLES;

This was the missing piece of the puzzle for me also! I've been spending at least an hour trying to figure out why it wasn't testing correctly. This was it.

Yeah, the check for a correct solution clearly needs to be fixed to accept 'Not a Triangle', since the word 'a' is never capitalized unless it's the first word in a sentence.

Can you post your solution for this because I am not getting exactly where I am getting wrong.

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' WHEN A != B OR B != C OR A != C THEN 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;

The full condition for a trinagle exist is:
| b - c | < a < b + c
| a - c | < b < a + c
| a - b | < c < a + b
If you negate this condition, the row is not a triangle.

I was getting crazy wondering why my query was not passing the test cases.

Your tip save my time.

i had to change this code:

/*Enter your query here.*/SELECTIF(A=BANDA=C,'Equilateral',IF(A=BORA=CORB=C,'Isosceles',IF(A+B<CORA+C<BORB+C<A,'Not A Triangle','Scalene')))FROMTRIANGLES

To this other:

/*Enter your query here.*/SELECTIF(A+B<=C,'Not A Triangle',IF(A=BANDA=C,'Equilateral',IF(A=BORA=CORB=C,'Isosceles','Scalene')))FROMTRIANGLES

SELECT CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN 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 AND B != C AND C != A THEN 'Scalene' ELSE 'Not A Triangle' END ELSE 'Not A Triangle'END FROM TRIANGLES;

The solution below would still pass with A=100, B=1, and C=1, which isnt correct.

SELECT
CASE WHEN A + B <= C
THEN "Not A Triangle"
WHEN A=B AND B=C THEN "Equilateral"
WHEN A!=B AND B!=C AND A!=C THEN "Scalene"
ELSE "Isosceles"
END
FROM TRIANGLES

## Type of Triangle

You are viewing a single comment's thread. Return to all comments →

Checking for the 'Not A Triangle' case should use <= as comparator, even though it is stated in the description that A+B should be strictly less than C.

You are right. The statement is not fully accurate.

You are right. I finally solved it but issue with the problem statement is what they say in problem is correct 'triangle inequality' whereas what they are asking for is incorrect. Equality exists for triangle with area zero. So still it is a triangle but zero area (Can be argued otherwise also) but problem statement is wrong.

Would like to correct my statement that triangle with area=0 is still a triangle is incorrect.Also thanks for the tip, I was wondering what am I doing wrong.

You are so right too. Brilliant thought. I also realized that Zero area is only true for the equality condition (Ex. A+B=C) but not for the less than case (A+B

same, I was losing it over where I am going wrong!

I would disagree as triangle is defined by 3 points on the plane that are not on the same line. Your area "zero" triagle is not a triagle as all 3 point are in line which violates definition of the triangle.

yes offcourse sum of any two sides must be greater than the third one.

SELECT CASE

WHEN A + B > C THEN CASE WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR B = C OR A = C THEN 'Isosceles' WHEN A != B OR B != C OR A != C THEN 'Scalene' END

ELSE 'Not A Triangle' END FROM TRIANGLES;

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' WHEN A != B OR B != C OR A != C THEN 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;

YOU HAVE TO CHECK FOR ALL COMBINATIONS OF THE CONDITION

A != B OR B != C OR A != C also can be not triangle

(3, 4, 5) is a triangle, but (3, 4, 50) is not.

but this fails in the first condition in the query CASE WHEN A + B > C AND A+C>B AND B+C>A so the query is correct

select case when A+B > C AND A=B AND B=C AND A=C then 'Equilateral' when A+B > C AND A=B OR B=C OR A=C then 'Isosceles' when A+B > C AND A!=B then 'Scalene' else 'Not A Triangle' End from TRIANGLES

TRY THIS.........

IF (A,B,C)= (20,1,1) then foolow your code the result will be "Isosceles'

But in fact this is not a triangle because A< B+C So the point is you forget the condition B+C>A AND A+C>B

But i wonder why the code is accepted in this case

I dont understand your meaning, it says in every sub that A+B>C

if "Case1: A + B > C AND A+C>B AND B+C>A" is true then only after that you have to verify "case2: A != B OR B != C OR A != C" which kind of triangle it is. If it is not a valid triangle, case1 will be false and you don't have to worry about the rest cases.

that is the raason he gave when A+B>c;

no, it is the case of a scalene triangle. but a case where A+B

A!=B AND B!=C I think this would work

check in example it is scalene type

No, It will be a traingle because we hve already checked whether it is a triangle or not

when you use "WHEN A != B OR B != C OR A != C THEN 'Scalene'" why do you use "OR"? shouldn't it be "AND" because ALL 3 sides are not equal? so it will be "WHEN A != B AND B != C THEN 'Scalene'".

WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR B = C OR A = C THEN 'Isosceles' ELSE 'Scalene'

Why does not A = B = C work for Equilateral? Whats the difference between A = B and B = C?

when A=B=C execute then if A=B then it return boolean value if true then 1 else 0 then it compare 1=c

e.g. (10,10,10)

when execute A=B=C then (10=10)=10 take as (10=10) return 1 because its true then in next stape it compare 1=10 in next step and return false

This explanation is not true. counter example: ((A=B)=(B=C)) doesnt work. step 1: ((A=B)=(B=C)) -> (1) = (B=C) step 2: ((1) = (B=C)) -> (1) = (1) step 3: (1) = (1) -> 1 But doesnt work

this is simple math logic if A=B and B=C it means A=C....

operator overlosding dont work here

Yes you are right AND should be used instead of OR, but even if you use OR then the test case is been submitted..., how is this possible, or there is a fault in the question?

You could also not write the last condition before 'Not A Triangle' to simplify the Query:

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;

If A = B, it doesn't say anything about C (it is not sure than the triangle is ISOSCELES; in fact, it could be EQUILATERAL if A = C). Here's my version of the script: 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 AND A !=C OR B = C AND B!=A OR A = C AND A!=B THEN 'Isosceles' ELSE 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;

Hope you enjoy it, fellas!!

FOR ISOSCELES shouldn't it be A=B and B!=C and so on ? Otherwise iscosceles and equailateral might overlap

It's not necessary because in that case, if A = B AND B = C, which is the first case, then it's an equilateral triangle. That's why I put that case as the first one so it won't get to the isosceles triangle case.

You don't need to have multiple CASE statements next to each other or nested CASEs. If you check the conditions in the right order, only one CASE statement with multiple WHENs will do the job:

This is for MS SQL Server.

Hi, could anyone please point out the mistake in my query wriiten below. I am not able to figure out why it says wrong answer!

select case when A+B <=C OR B+C <=A OR C+A <=B then 'not a triangle' when A=B and B=C and C=A then 'Equilateral triangle' when A=B or B=C or C=A then 'Isosceles triangle' else 'Scalene triangle' end from TRIANGLES;

Thank you for replying. Although, I did try that too. It did not work.

The sql query conditions are correct.The statements in the then of sql case should be modified.Change 'Equilateral triangle' to 'Equilateral' and do other changes as below.

select case when A+B <=C OR B+C <=A OR C+A <=B then 'Not A Triangle' when A=B and B=C and C=A then 'Equilateral' when A=B or B=C or C=A then 'Isosceles' else 'Scalene' end from TRIANGLES;

Your Query is Correct but the output should match with question

'not a triangle' -> "Not A Triangle" 'Equilateral triangle' -> "Equilateral" 'Isosceles triangle' -> "Isosceles" 'Scalene triangle' -> "Scalene"

Why write end from triangles?

end is the ending of case statement started at the start of query and from triangle is the part of 'select-from-where' clause in which where is replaced by triangles which is the name of our table/relation in which three sides of triangles are stored.

select case when a+b<=c and b+c<=a and a+c<=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 from triangles

i wrote this code but then why is it showing error for mysql

1) Compare casing of letters in printed strings with those of expected output 2) The 'Not A Triangle' conditions appear to be incorrect

did you get the answer for this ?

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 FROM TRIANGLES;

THIS WILL WORK NOW IN MYSQL!!!!

It does because the loop will iterate without checking condition

Hi, Could you please tell me what's the difference between your code and the code below?

SELECT CASE WHEN A + B <= C OR B + C <= A OR C + A <= B THEN 'Not a Triangle' WHEN A = B OR B = C OR A = C THEN 'Isosceles' WHEN A = B AND B = C And C = A THEN 'Equilateral' ELSE 'Scalene' END FROM TRIANGLES

First, you should check case of Equilateral before case of Isosceles. Second, this is very stupid that you must use "Not A Triangle"

why WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle should be the first one?

I have exactly this and it still says it's wrong.

end FROM Triangles

Edit: Found out it was because the 'a' in 'Not a Triangle' wasn't capitalized. That's more nit-picky than the sql language itself!

I was facing same issue, this helped. Thanks for a good catch.

I have the exact same thing, good job. Only difference is that I would get an error if I didn't run parenthesis in the conditions like (a+b) <= c. Adding paretheses gave me the right answer....

WHEN A = B OR A = C OR B = C THEN 'Isosceles'

I don't understand this part

In case A=B, C can equal A and this would make it an equilateral, shouldn't you say and C!= A??

thanks a lot

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 and A!=C and B!=C then 'Scalene' else 'Isosceles' end from TRIANGLES

THANK YOU! easy to read

Why doesn't it work for MySQL?

Okay, it works for that too. Thank You

I came up with nearly the same exact code. However I am receiving errors. I am getting "isoceles" returned instead of "Not a triangle" for one of the test cases.

SELECT CASE WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR A = C OR B = C THEN 'Isosceles' WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle' ELSE 'Scalene' END FROM TRIANGLES;

HELP??

Hi Antoniro, I wrote exact the same answer as yours. And I compared the each result in my output with the expected one. Everything is correct but my answer is wrong. The only difference is I have a 16th line which is an empty line in my output. Do you have any idea for this?

Thanks, Alice

whay have you written CASE twice :)

For Scalene Triangle shouldn't it be like this?

If A!=B OR B!=C OR A!=C then for A!=B, B=C or A=C can happen.

However, hackerrank is accepting both answers.

How is

WHEN A != B OR B != C OR A != C THEN 'Scalene' possible in 20,20,21 ? You should use AND condition right?

YES you are correct AND should be used, but if you use OR the test is getting submitted I dont know how?

can you please tell me, why not just

ELSE 'Not A Triangle'But,

END ELSE 'Not A Triangle' ENDSELECT 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' WHEN A != B OR B != C OR A != C THEN 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;

Here, there are two case statements are available, inside CASE doesn't have any else statement. First END is for inside CASE and second END is for outside case.

or may be

Hi, I don't understand the last bit, it has two END statements. I'm not familiar yet with CASE. Could you please elaborate your thought process here? Thank you!

if sum of any two edges is greater then third edge, we can say it forms a triangle. So there is no need to check B+C>A , A+C>B. Because If A+B>C, it is enough to say they are going to form a triangle.

should be WHEN A != B and B != C and A != C THEN 'Scalene'

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' WHEN A != B and B != C and A != C THEN 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;

Small suggestion:- For Scalene triangle, no two sides must simultaneously be equal. So, A != B and B != C and A != C might be the complete condition.

Why have you used 'OR' to find Scalene triangle, I think 'AND' should be used there.

will not work for cases like 12 10 1 <- This will produce output as scalene byt it should not be a triangle.

SELECT * FROM ( SELECT (CASE WHEN (A + B <= C) OR (B + C <= A) OR (C + A <= B) THEN 'Not A Triangle' WHEN (A = B AND B = C AND C = A) THEN 'Equilateral' WHEN (A = B AND C <> A) OR (A <> B AND B = C ) OR (A = C AND B <> C ) THEN 'Isosceles' WHEN (A <> B AND B <> C AND C <> A) THEN 'Scalene' END ) AS TRIANGLE_TYPE FROM TRIANGLES )Z;

SELECT CASE WHEN A+B>C THEN CASE WHEN A=B AND B=C Then 'Equilateral' When A=B OR A=C OR B=C THEN 'Isosceles' When A!=B OR B!=C OR C!=A Then 'Scalene' END ELSE 'Not a Triangle' END FROM Triangles;

I wrote this, compared the answer but the compiler claims a fault in it.

why we are using** A + B > C**

i can't able to understand why you mentioning

"when A+B>C"at startiting can you explain it why?Thanks a lot.

We do not require a condition to check for Scalene, we can directly write ELSE instead of the condition.

SELECT CASE WHEN ((A + C > B) and (A + B >C) and (C + B >A)) THEN CASE WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR B = C OR A = C THEN 'Isosceles' WHEN A != B OR B != C OR A != C THEN 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;

This is a better solution pravin!

Thank you!

This got me too

Is it guaranteed that C will always be the greatest side?

I do not think so. The table is small so you can look at its contents yourself.

you'll have to check for all the 3 conditions as in (A+B>C AND B+C>A AND C+A>B)

not AND but OR

Thank you. .got it cheers

Thanks

Thank you! This was the missing test case in my solution.

Thank You!

It's assumed that anyone attempting this challenge understands basic Geometry. Any rules will be stated in the Problem Statement at the top of the page. The Explanation section is not stating a rule, it's stating an inequality relevant to the respective A, B, and C values for that Sample Case. The reason why those values do not form a triangle is because 27 is a number that is less than 30. There is a difference between the two numbers. If A and B added up to 30, then the Explanation would say that A + B = C because that would be the immediate reason causing it to not be a triangle.

And yet they are stated like rules in the description... I too was stuck as were all these other people. Perhaps you could be a little less stubborn and fix a clearly misleading description.

I'll just leave this here

https://en.wikipedia.org/wiki/Triangle_inequality

it's technically only assumed they know sql :P, unless you mean it is word of god? in that case it is whatever you say it is I guess

"It's assumed that anyone attempting this challenge understands basic Geometry".

I've come here to learn/revise sql, not learn/revise geometry. I think it's odd that the rules at the top cover the basic triangle types that most of us would remember from school, but not the triangle inequality stuff that fewer of us would recall, yet which is only alluded to by example. I didn't know about the latter at all (or had clean forgotten) and just added an 'else' for it.

Yes , thanks for the hint, admin shoud provide proper info.

Thanks Dude

Thank You

The case A + B = C corresponds to a Triangle of zero area (zero angles). The technical definition will sometimes allow this, but this problem does not. So, based on the result, the problem is actually stated correctly. The problem is we don't know which axioms she is using.

select if((A + B > C),if(( A=B and B=C),'Equilateral', if(( A=B or A=C or B=C),'Isosceles',if((A!=B and B!=C),'Scalene','Not A Triangle'))),'Not A Triangle') as types from TRIANGLES;

My solution:

wasting 10 minutes to figure out what's wrong; typed "a" instead of "A" at Not A Triangle :D

Thank you! Makes sense now becuase it was expecting that output

This was the missing piece of the puzzle for me also! I've been spending at least an hour trying to figure out why it wasn't testing correctly. This was it.

Yeah, the check for a correct solution clearly needs to be fixed to accept 'Not a Triangle', since the word 'a' is never capitalized unless it's the first word in a sentence.

Thanks! I did the same mistake.

Can you post your solution for this because I am not getting exactly where I am getting wrong.

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' WHEN A != B OR B != C OR A != C THEN 'Scalene' END ELSE 'Not A Triangle' END FROM TRIANGLES;thanks for comment after use of <= as comparator i pass the test

Thanks for the tip!

It's an error. When A+B=C - It's a line segment, but not a triangle..

No, the statement is right as per Euclidean Geometry. See this.

The condition A+B = C is basically 3 points on the same line. You can't really call it a triangle. If so, then one can refer to a line as any polygon.

A + B > C makes more sense because it's right.

The full condition for a trinagle exist is: | b - c | < a < b + c | a - c | < b < a + c | a - b | < c < a + b If you negate this condition, the row is not a triangle.

I was getting crazy wondering why my query was not passing the test cases.

Your tip save my time.

i had to change this code:

To this other:

to get pass the test cases

thanks b0ss

I literally just translated the condition in the code - "not larger" so I used !>, and it worked the first time.

SELECT CASE WHEN A + B > C AND A + C > B AND B + C > A THEN 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 AND B != C AND C != A THEN 'Scalene' ELSE 'Not A Triangle' END ELSE 'Not A Triangle'END FROM TRIANGLES;

The solution below would still pass with A=100, B=1, and C=1, which isnt correct.

SELECT CASE WHEN A + B <= C THEN "Not A Triangle" WHEN A=B AND B=C THEN "Equilateral" WHEN A!=B AND B!=C AND A!=C THEN "Scalene" ELSE "Isosceles" END FROM TRIANGLES