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
- coding
- full request
- HTML
- leetcode
- PYTHON
- conflict
- CSS
- 버전충돌
- early stopping
- RLIKE
- 편향-분산 교환
- programmers
- 코딩공부
- 깃헙협업
- 교차 엔트로피
- branch
- L2정규화
- hackerrank
- L1정규화
- window function
- 온라인협업
- github
- mysql
- AWS
- elastic net
- 선형 모형
- sql
- merge
- Git
- 클라우드컴퓨팅
Archives
- Today
- Total
Im between cherry
Hackerrank | MySQL | Symmetric Pairs 본문
Symmetric Pairs
Symmetric Pairs | HackerRank
Write a query to output all symmetric pairs in ascending order by the value of X.
www.hackerrank.com
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