Programing Language/SQL

Symmetric Pairs

Data-SSung 2025. 5. 23. 01:03
반응형

 

  • 문제 point
    • symmetric 개념 익히기 x1 = y2 and x2 =y1
    • x<=y 인 조합에 대해서 x 오름차순 정렬해서 구하기
      • 첫번째 x<y 경우에 대해서 작업 구하기
      • 두번째 x=y(이런 경우가 두 개 있어야 함)
select c.x, c.y
from (
    -- x<y
    select a.x, a.y
    from Functions a
    inner join Functions b
        on a.x = b.y
            and a.y = b.x
    where a.x < a.b

    union 

    -- x=y
    select x,y
    from Functions
    where x = y
    group by x,y
    having count(*)>=2
) c
order by c.x

 

반응형