본문 바로가기
언어

Symmetric Pairs

by 땅호720 2024. 6. 19.

-- f(20) = 21일 때, f(21) = 20이면 페어
-- 둘 중 x가 y보다 작은 경우만 출력

-- self pair 묶지 않도록 rn 할당

with cte as(
    select *,
    row_number() over() as rn
    from functions
)

select distinct ori.x, ori.y
from cte ori
inner join cte sub on ori.x=sub.y and ori.y=sub.x and ori.rn != sub.rn
where ori.x <= ori.y
order by ori.x

 

'언어' 카테고리의 다른 글

recursive & repeat  (0) 2024.06.25
interviews  (0) 2024.06.20
with as  (0) 2024.06.18
mysql에 pivot 없음  (1) 2024.06.14
basic join: top competitors (medium)  (1) 2024.06.14