Skip to content

Commit ced4c6e

Browse files
[ADD] JOINS module with classes, resources and tasks
1 parent 24d7d6d commit ced4c6e

12 files changed

+6198
-0
lines changed

classes/16-union.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SELECT *
2+
FROM continent;
3+
4+
SELECT code, name, '123'
5+
FROM continent
6+
WHERE name LIKE '%America'
7+
UNION
8+
SELECT code, name, 'Another thing'
9+
FROM continent
10+
WHERE code IN (3, 5)
11+
ORDER BY name ASC;

classes/17-where.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT *
2+
FROM country;
3+
4+
SELECT
5+
a.name AS country,
6+
b.name AS continent
7+
FROM country AS a, continent AS b
8+
WHERE a.continent = b.code
9+
ORDER BY b.name ASC;

classes/18-inner-join.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT *
2+
FROM country;
3+
4+
SELECT
5+
a.name AS country,
6+
b.name AS continent
7+
FROM country AS a
8+
INNER JOIN continent AS b ON b.code = a.continent
9+
ORDER BY b.name ASC;

classes/20-alter-sequence.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT *
2+
FROM continent;
3+
4+
ALTER SEQUENCE continent_code_seq RESTART WITH 10;
5+
6+
INSERT INTO continent (name)
7+
VALUES ('North Asia');

classes/21-full-outer-join.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SELECT *
2+
FROM continent;
3+
4+
INSERT INTO continent (name)
5+
VALUES ('Central Asia'), ('South Asia');
6+
7+
-- country a (name, continent)
8+
-- continent b (name)
9+
SELECT
10+
a.name AS country,
11+
a.continent AS continent_code,
12+
b.name AS continent_name
13+
FROM country AS a
14+
FULL OUTER JOIN continent AS b ON b.code = a.continent
15+
ORDER BY a.name DESC;

classes/22-right-outer-join.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT *
2+
FROM continent;
3+
4+
SELECT
5+
a.name AS country,
6+
a.continent AS continent_code,
7+
b.name AS continent_name
8+
FROM country AS a
9+
RIGHT JOIN continent AS b ON b.code = a.continent
10+
WHERE a.continent IS NULL;

classes/23-aggregations-joins.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SELECT
2+
b.name AS continent,
3+
COUNT(*) AS count
4+
FROM country AS a
5+
INNER JOIN continent AS b ON b.code = a.continent
6+
GROUP BY b.name
7+
UNION
8+
SELECT
9+
b.name AS continent,
10+
0 AS count
11+
FROM country AS a
12+
RIGHT JOIN continent AS b ON b.code = a.continent
13+
WHERE a.continent IS NULL
14+
GROUP BY b.name
15+
ORDER BY count ASC;

0 commit comments

Comments
 (0)