Symmetric Pairs

Sort by

recency

|

1562 Discussions

|

  • + 0 comments

    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

    UNION

    SELECT x, y FROM Functions WHERE x = y GROUP BY x, y HAVING COUNT(*) > 1 ORDER BY x;

  • + 1 comment

    SELECT f1.X, f1.Y FROM Functions f1 INNER JOIN Functions f2 ON f1.X = f2.Y AND f1.Y = f2.X WHERE f1.X <= f1.Y GROUP BY f1.X, f1.Y HAVING COUNT(*) > 1 OR f1.X < f1.Y ORDER BY f1.X;

  • + 0 comments

    SELECT f.x,f.y from Functions f inner join Functions f1 on f.X = f1.Y and f.Y = f1.X where f.x <= f.y group by f.x,f.Y having f.x < f.y or (count(f1.x)>1) order by x

  • + 0 comments

    with cte as (select * ,row_number() over(order by x ) as r from Functions)

    select distinct a.x , a.y from cte a join cte b on a.x=b.y and a.y = b.x and a.r != b.r and a.x <= a.y order by a.x

  • + 0 comments
    WITH sorted AS (
        SELECT 
            X,
            Y,
            LEAD(X) OVER (ORDER BY LEAST(X,Y), GREATEST(X,Y)) AS next_X,
            LEAD(Y) OVER (ORDER BY LEAST(X,Y), GREATEST(X,Y)) AS next_Y
        FROM Functions
    )
    SELECT 
        LEAST(X, Y) AS X,
        GREATEST(X, Y) AS Y
    FROM sorted
    WHERE X = next_Y AND Y = next_X
    ORDER BY X;