Symmetric Pairs

Sort by

recency

|

1534 Discussions

|

  • + 0 comments

    can anyone tell me what is wrong with this: with cte as (select a.X as X, a.Y as Y, b.X as X_new, b.Y as Y_new from functions as a join functions as b on a.Y = b.X) select distinct X, Y from cte where X = Y_new and X <= Y order by X

  • + 0 comments

    what is the error in this : select distinct t1.X,t1.Y from functions t1 cross join functions t2

    where t1.X=t2.Y and t1.Y=t2.X and t1.X<=t1.Y order by t1.X

  • + 0 comments
    WITH
    cte AS(
            SELECT *, ROW_NUMBER() OVER(ORDER BY x,y) AS rn
            FROM functions
        )
        
    SELECT DISTINCT f1.x, f1.y
    FROM cte f1
    JOIN cte f2 ON f1.x = f2.y AND f2.x = f1.y AND f1.rn <> f2.rn
    WHERE f1.x <= f1.y
    ORDER BY f1.x;``
    
  • + 0 comments

    **Check out this video for 10 Solved SQL Hackerrank Solutions - https://www.youtube.com/watch?v=sUMUDJUWDZI **

  • + 0 comments

    MySQL

    with 
        rown as
        (
            select
                x,
                y,
                row_number() over (order by x) idx
            from
                functions
        )
    select distinct
        f1.x,
        f1.y
    from
        rown f1,
        rown f2
    where
        f1.x = f2.y and
        f2.x = f1.y and
        f1.x <= f1.y and
        f1.idx <> f2.idx
    order by
        f1.x asc,
        f1.y;