-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL.text
132 lines (105 loc) · 2.96 KB
/
SQL.text
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--SELECT *
FROM north_american_cities
WHERE Country = 'Canada';
--SELECT *
FROM North_american_cities
WHERE Country = "United States"
Order BY Latitude DESC
--SELECT City, Longitude FROM North_american_cities
WHERE Longitude < -87
ORDER BY Longitude ASC;
--SELECT City
FROM North_american_cities
WHERE Country = 'Mexico'
ORDER BY Population DESC
LIMIT 2
--SELECT City
FROM North_american_cities
WHERE Country = 'United States'
ORDER BY Population DESC
LIMIT 2
OFFSET 2
-- SELECT *
FROM Movies
JOIN Boxoffice ON Movies.Id = Boxoffice.Movie_id
-- SELECT Title, Domestic_sales, International_sales
FROM Movies
JOIN Boxoffice ON Movies.Id = Boxoffice.Movie_i
WHERE International_sales > Domestic_sales;
--SELECT Title, Rating
FROM Movies
JOIN Boxoffice ON Movies.Id = Boxoffice.Movie_id
ORDER BY Rating DESC
--SELECT DISTINCT Building
FROM Employees
--SELECT *
FROM Buildings
SELECT DISTINCT Building_name, Role
FROM Buildings
LEFT JOIN Employees
ON Building_name = Building
--SELECT Role, Name
FROM employees
WHERE Building IS NULL
--SELECT Building_name
FROM Buildings
LEFT JOIN Employees ON Buildings.Building_name = Employees.Building
WHERE Building IS NULL
--SELECT Title, (Domestic_sales + International_sales)/1000000 AS Total_sales_milj
FROM movies
JOIN Boxoffice ON Movies.Id = Boxoffice.Movie_id
--SELECT Title, Rating *10 AS Rating_perc
FROM movies
JOIN Boxoffice ON Movies.Id = Boxoffice.Movie_id
--SELECT *
FROM movies
WHERE Year % 2 = 0
Lesson 10
--SELECT MAX(Years_employed) FROM employees
--SELECT Role, AVG(Years_employed) FROM employees GROUP BY Role
--SELECT Building, SUM(Years_employed) FROM employees GROUP BY Building
Lesson 11
--SELECT COUNT(Name), Building FROM employees WHERE Role = 'Artist' GROUP BY Building
--SELECT COUNT(Name), Building, Role FROM employees GROUP BY Role
--SELECT SUM(Years_employed) FROM employees Where Role = 'Engineer'
Lesson 12
--SELECT COUNT(Title) AS Total_movies, Director FROM movies AS m GROUP BY Director
--SELECT SUM(Domestic_sales + International_sales) AS Total_sales, Director
FROM movies AS m JOIN Boxoffice AS b ON m.Id = b.Movie_id GROUP BY Director
Lesson 13
--INSERT INTO Movies
(Title, Director, Year, Length_minutes)
VALUES ('Toy Story 4', 'John Lasseter', 2022, 97)
--INSERT INTO Boxoffice
(Movie_id, Rating, Domestic_sales, International_sales)
VALUES (15, 8.7, 340000000, 270000000)
Lesson 14
--UPDATE Movies
SET Director = 'John Lasseter'
WHERE Title = "A Bug's Life"
--UPDATE Movies
SET Year = 1999
WHERE Title = "Toy Story 2"
--UPDATE Movies
SET Director = 'Lee Unkrich',
Title = 'Toy Story 3'
WHERE Title = "Toy Story 8"
Lesson 15
--DELETE FROM movies WHERE Year < 2005
--DELETE FROM movies
WHERE Director = 'Andrew Stanton'
Lesson 16
--CREATE TABLE Database (
Name TEXT
Version FLOAT
Download_count INTEGER
)
Lesson 17
--ALTER TABLE movies
ADD Aspect_ratio FLOAT;
--ALTER TABLE movies
ADD Language TEXT
DEFAULT English;
Lesson 18
--DROP TABLE IF EXISTS movies;
--DROP TABLE IF EXISTS Boxoffice;