# 문제
https://leetcode.com/problems/triangle-judgement/description/
# 문제 설명
# 삼각형이 만들어지기 위한 조건
(직각삼각형이 만들어지기 위한 조건이 아니다!)
가장 큰 변이 나머지 두 변의 합보다 작아야 한다
예를 들어서 x,y,z,가 있고 최대값이 x라고 했을때
x < y + z
# 핵심 개념
greatest(숫자)를 하면 최대값을 출력할 수 있다
with cte as (
select *,
greatest(x,y,z) as max_value,
case when x = greatest(x,y,z) and x < (y+z) then 'Yes'
when y = greatest(x,y,z) and y < (x+z) then 'Yes'
when z = greatest(x,y,z) and z < (x+y) then 'Yes'
else 'No' end as triangle
from Triangle
)
select *
from cte
[ 결과 ]
# 정답 코드
with cte as (
select *,
case when x = greatest(x,y,z) and x < (y+z) then 'Yes'
when y = greatest(x,y,z) and y < (x+z) then 'Yes'
when z = greatest(x,y,z) and z < (x+y) then 'Yes'
else 'No' end as triangle
from Triangle
)
select *
from cte