언어

Symmetric Pairs

땅호720 2024. 6. 19. 13:44

-- 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