Algorithms 🚀/HackerRank

[MySQL/해커랭크] Symmetric Pairs

728x90

www.hackerrank.com/challenges/symmetric-pairs/problem

 

Symmetric Pairs | HackerRank

Write a query to output all symmetric pairs in ascending order by the value of X.

www.hackerrank.com

JOIN을 이용한 간단한 문제입니다.

 

문제의 조건은 X1 = Y2 && X2 = Y1 이여야 합니다.

 

select f1.x, f1.y
from functions f1 join functions f2
on (f1.x = f2.y and f2.x = f1.y)
group by f1.x, f1.y
having count(*) > 1  or f1.x < f1.y
order by f1.x
728x90