Writing SQL code to recognize when three input lengths form a triangle I tried to do a SQL code that recognize automatically when we have a triangle from three different length inputs $A$, $B$, and $C$ for an HackerRank contest but it seems I'm wrong in my attempt. I ouput the following results :

10 10 10 Equilateral 
11 11 11 Equilateral 
30 32 30 Isoceles 
40 40 40 Equilateral 
20 20 21 Isoceles 
21 21 21 Equilateral 
20 22 21 Scalene 
20 20 40 Isoceles 
20 22 21 Scalene 
30 32 41 Scalene 
50 22 51 Scalene 
20 12 61 Not A Triangle 
20 22 50 Not A Triangle 
50 52 51 Scalene 
80 80 80 Equilateral 


One was guilty : $(20,20,40)$ but may I say a triangle is an object with three sides where the sum of two is at least equal or strictly equal to the last side it doesn't change anything : I'm wrong.

Here is the code I tried :

SELECT A,B,C,
    CASE WHEN A=B AND A=C THEN 'Equilateral'
         WHEN (A+B&gt;=C AND A+C&gt;=B AND B+C&gt;=A) AND
              (A=B OR A=C OR B=C) THEN 'Isoceles'
         WHEN (A+B&gt;=C AND A+C&gt;=B AND B+C&gt;=A) THEN 'Scalene'
         ELSE 'Not A Triangle' 
    END   
FROM TRIANGLES


But even with strict inequalities the following output is wrong :

10 10 10 Equilateral 
11 11 11 Equilateral 
30 32 30 Isoceles 
40 40 40 Equilateral 
20 20 21 Isoceles 
21 21 21 Equilateral 
20 22 21 Scalene 
20 20 40 Not A Triangle 
20 22 21 Scalene 
30 32 41 Scalene 
50 22 51 Scalene 
20 12 61 Not A Triangle 
20 22 50 Not A Triangle 
50 52 51 Scalene 
80 80 80 Equilateral 


Update June, 2nd

One answer that works is the following :

SELECT 
    CASE WHEN A + B &gt; C AND A+C&gt;B AND B+C&gt;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;


With the following output: 
As you can see, it's the same. I don't understand :

Equilateral 
Equilateral 
Isosceles 
Equilateral 
Isosceles 
Equilateral 
Scalene 
Not A Triangle 
Scalene 
Scalene 
Scalene 
Not A Triangle 
Not A Triangle 
Scalene 
Equilateral
As @uniquesolution says in the comments, the better approach is to ensure trianglehood first, and classify triangles second.  So:


If any two sides fail to exceed the length of the third, it is not a triangle.  Else...
If all three sides are equal, the triangle is equilateral.  Else...
If two sides are equal, the triangle is isosceles.  Else...
The triangle is scalene.
TRY THIS:
SELECT CASE
    WHEN A = B and B = C and C = A THEN 'Equilateral'
    WHEN (A=B or A=C or B = C) and (A+B &gt; C AND A+C&gt;=B AND B+C&gt;=A)THEN 'Isosceles'
    WHEN (A&lt;&gt;B and B&lt;&gt;C and C&lt;&gt;A) and (A+B &gt; C AND A+C&gt;=B AND B+C&gt;=A) THEN 'Scalene'
    ELSE 'Not A Triangle'
END AS Dummy
FROM TRIANGLES;

Which returns
Equilateral 
Equilateral 
Isosceles 
Equilateral 
Isosceles 
Equilateral 
Scalene 
Not A Triangle 
Scalene 
Scalene 
Scalene 
Not A Triangle 
Not A Triangle 
Scalene 
Equilateral