🤔 문제 분석
1. Two pairs (X1, Y1) and (X2, Y2) are said to be symmetric pairs if X1 = Y2 and X2 = Y1.
2. Write a query to output all such symmetric pairs in ascending order by the value of X.
3. List the rows such that X1 ≤ Y1.
💡 풀이
SELECT A.X, A.Y
FROM Functions AS A
JOIN Functions AS B ON A.Y = B.X AND A.X = B.Y
GROUP BY A.X, A.Y
HAVING COUNT(*) > 1 OR A.X < A.Y
ORDER BY A.X
'코딩테스트 > 해커랭크 SQL' 카테고리의 다른 글
[해커랭크/MySQL] 44. Placements (0) | 2023.04.13 |
---|---|
[해커랭크/MySQL] 43. Weather Observation Station 17 (0) | 2023.04.10 |
[해커랭크/MySQL] 42. Weather Observation Station 16 (0) | 2023.04.10 |
[해커랭크/MySQL] 41. Weather Observation Station 15 (0) | 2023.03.21 |
[해커랭크/MSSQL] 40. Ollivander's Inventory (0) | 2023.03.21 |
댓글