We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In this sql, I can't find the condition that we have to write only one row about same diagonal pairs
this sql is answer. but i can't understand why i have to use group by
`with cte as (
select x, y, row_number() over (order by x) as rn
from functions
)
select f1.x, f1.y
from cte f1
join cte f2 on f1.x = f2.y and f1.y = f2.x and f1.rn != f2.rn
where f1.x <= f1.y
group by f1.x, f1.y
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Symmetric Pairs
You are viewing a single comment's thread. Return to all comments →
In this sql, I can't find the condition that we have to write only one row about same diagonal pairs this sql is answer. but i can't understand why i have to use group by `with cte as ( select x, y, row_number() over (order by x) as rn from functions ) select f1.x, f1.y from cte f1 join cte f2 on f1.x = f2.y and f1.y = f2.x and f1.rn != f2.rn where f1.x <= f1.y group by f1.x, f1.y