Symmetric Pairs

  • + 0 comments
    with cte as(
    select *,
    case 
        when t.x=t.y and  (SELECT COUNT(*) FROM functions AS temp WHERE temp.x = t.y AND temp.y = t.x) > 1 then 'true'
        when t.x<t.y and (select count(*) from functions as temp where temp.x=t.y and temp.y=t.x)>0 then 'true'
        else ''
        end as flag
    from functions as t
    group by x,y 
    
    )
    select x,y
    from cte
    where flag='true'
    order by x