Symmetric Pairs

  • + 1 comment
    with functions_ranked as (
    select x, y, row_number() over(order by x) as rn_idx
    from functions),
    
    
    joined_pairs as (
    select t1.x as x1, t1.y as y1, t2.x as x2, t2.y as y2
    from functions_ranked t1
    join functions_ranked t2
    on t1.rn_idx != t2.rn_idx
    and t1.x = t2.y
    and t1.y = t2.x)
    
    select distinct x1, y1
    from joined_pairs
    where x1<=y1
    order by x1