Skip to content

Commit

Permalink
task 59
Browse files Browse the repository at this point in the history
  • Loading branch information
BEPb committed Feb 10, 2023
1 parent ce041db commit 2480558
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
56. 15 дней изучения SQL - [15 Days of Learning SQL](./tasks/56.md)
57. Планирование проекта SQL - [SQL Project Planning](./tasks/57.md)
58. Места размещения - [Placements](./tasks/58.md)
59. Симметричные пары - [Symmetric Pairs](./tasks/59.md)


## В процессе... , будет дополнено)
Expand Down
47 changes: 47 additions & 0 deletions tasks/59.md
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)

---

0 comments on commit 2480558

Please sign in to comment.