-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
### | ||
|
||
<img src="./art/59.png" alt="solution" > | ||
|
||
#### eng: | ||
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. | ||
|
||
|
||
#### рус: | ||
Вам дана таблица «Функции», содержащая два столбца: X и Y. | ||
|
||
Две пары (X1, Y1) и (X2, Y2) называются симметричными парами, если X1 = Y2 и X2 = Y1. | ||
|
||
Напишите запрос, чтобы вывести все такие симметричные пары в порядке возрастания значения X. Перечислите строки, такие что X1 ≤ Y1. | ||
|
||
#### код с коментариями: | ||
```sql | ||
SELECT f1.x, f1.y from functions f1 | ||
INNER JOIN functions f2 | ||
WHERE (f2.x = f1.y) | ||
AND (f1.x = f2.y) | ||
GROUP BY f1.x, f1.y | ||
HAVING ((f1.x = f1.y) AND (COUNT(*) > 1)) | ||
OR (f1.x < f1.y) | ||
ORDER BY f1.x; | ||
``` | ||
|
||
#### код для hackerrank: | ||
```sql | ||
SELECT f1.x, f1.y from functions f1 | ||
INNER JOIN functions f2 | ||
WHERE (f2.x = f1.y) | ||
AND (f1.x = f2.y) | ||
GROUP BY f1.x, f1.y | ||
HAVING ((f1.x = f1.y) AND (COUNT(*) > 1)) | ||
OR (f1.x < f1.y) | ||
ORDER BY f1.x; | ||
``` | ||
|
||
|
||
#### На [главную](https://github.com/BEPb/hackerrank_sql#readme) | ||
|
||
--- |