Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- RLIKE
- 온라인협업
- leetcode
- merge
- early stopping
- 깃헙협업
- sql
- github
- coding
- 클라우드컴퓨팅
- HTML
- AWS
- L2정규화
- mysql
- 선형 모형
- branch
- full request
- 버전충돌
- hackerrank
- Git
- window function
- elastic net
- programmers
- PYTHON
- 교차 엔트로피
- conflict
- L1정규화
- 코딩공부
- CSS
- 편향-분산 교환
Archives
- Today
- Total
Im between cherry
Hackerrank | MySQL | Symmetric Pairs 본문
Symmetric Pairs
You are given a table, Functions, containing two columns: X and Y.
Two pairs (X1, Y1) and (X2, Y2) are said to be symmetric pairs if X1 = Y2 and X2 = Y1.
Write a query to output all such symmetric pairs in ascending order by the value of X. List the rows such that X1 ≤ Y1.
-- 13, 13
SELECT X, Y
FROM functions
WHERE X = Y
GROUP BY X, Y
HAVING COUNT(*) = 2
UNION
SELECT f1.X, f1.Y
FROM functions AS f1
INNER JOIN functions AS f2 ON f1.X = f2.Y AND f1.Y = f2.X
WHERE f1.X < f1.Y
ORDER BY X
SELECT f1.x, f1.y
FROM functions AS f1
INNER JOIN functions AS f2 ON f1.x=f2.y AND f1.y=f2.x
GROUP BY f1.x, f1.y
HAVING count(*)>=2 or f1.x < f1.y
ORDER BY f1.x
'데이터분석 > practice_query' 카테고리의 다른 글
Hackerrank | MySQL | Challenges (0) | 2020.08.29 |
---|---|
Hackerrank | MySQL | Type of Triangle (0) | 2020.08.29 |
Hackerrank | MySQL | Draw The Triangle 2 (0) | 2020.08.29 |
Hackerrank | MySQL | Draw The Triangle 1 (0) | 2020.08.29 |
Hackerrank | MySQL | Average Population of Each Continent (0) | 2020.08.29 |
Comments