-
Notifications
You must be signed in to change notification settings - Fork 0
/
JOIN_Basics.sql
34 lines (28 loc) · 1.09 KB
/
JOIN_Basics.sql
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
31
32
33
34
--https://sqlbolt.com/lesson/select_queries_with_joins
--Find the domestic and international sales for each movie
SELECT Title, Domestic_sales, International_sales
FROM Boxoffice
INNER JOIN Movies
ON Boxoffice.Movie_id = Movies.id
--https://sqlbolt.com/lesson/select_queries_with_outer_joins
--List all buildings and the distinct employee roles in each building (including empty buildings)
SELECT Distinct Building_name, Role FROM Buildings
LEFT JOIN Employees
ON Building_name = Building;
--Find the names of the buildings that hold no employees
SELECT Building_name FROM Buildings
LEFT JOIN Employees
ON Building_name = Building
WHERE Role is NULL;
--https://sqlbolt.com/lesson/select_queries_with_expressions
--List all movies and their combined sales in millions of dollars
SELECT Title, (Domestic_sales + International_sales)/1000000 AS Total_Sales
FROM Boxoffice
INNER JOIN Movies
ON Boxoffice.movie_id = Movies.id;
--List all movies that were released on even number years
SELECT title, Year
FROM movies
JOIN boxoffice
ON movies.id = boxoffice.movie_id
WHERE Year % 2 == 0