Keep in mind that CASE statements are evaluated IN ORDER – the first WHEN clause that fits “wins” and no further evaluation is made. So:
with
triangles ( A, B, C ) as (
select 20, 20, 23 from dual union all
select 20, 20, 20 from dual union all
select 20, 21, 22 from dual union all
select 13, 14, 30 from dual
)
select A, B, C,
case
when A+B <= C or B+C <= A or C+A <= B 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 classification
from triangles
;
A B C CLASSIFICATION
--- --- --- --------------
20 20 23 Isosceles
20 20 20 Equilateral
20 21 22 Scalene
13 14 30 Not A Triangle
4 rows selected.
11
solved SQL query to classify triangles into Equilateral, Isosceles, etc