You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: SQL-Bolt/Practice.sql
+76-1
Original file line number
Diff line number
Diff line change
@@ -174,4 +174,79 @@ Join boxoffice b on b.movie_id=m.id;
174
174
-- List all movies that were released on even number years
175
175
Select title
176
176
From movies
177
-
Where year%2=0;
177
+
Where year%2=0;
178
+
179
+
--SQL Lesson 10: Queries with aggregates (Pt. 1)
180
+
-- Find the longest time that an employee has been at the studio
181
+
SELECT years_employed as year
182
+
FROM employees
183
+
Order by year desc
184
+
Limit1;
185
+
186
+
-- For each role, find the average number of years employed by employees in that role
187
+
SELECT role, avg(years_employed) as year
188
+
FROM employees
189
+
Group by role;
190
+
191
+
-- Find the total number of employee years worked in each building
192
+
SELECT building, sum(years_employed) as sum
193
+
FROM employees
194
+
Group by building;
195
+
196
+
-- SQL Lesson 11: Queries with aggregates (Pt. 2)
197
+
-- Find the number of Artists in the studio (without a HAVING clause)
198
+
SELECTCount(*)
199
+
FROM employees
200
+
Where role='Artist';
201
+
202
+
-- Find the number of Employees of each role in the studio
203
+
SELECT role, Count(*)
204
+
FROM employees
205
+
Group by role;
206
+
207
+
-- Find the total number of years employed by all Engineers
208
+
SELECTsum(years_employed) as sum
209
+
FROM employees
210
+
Where role='Engineer';
211
+
212
+
-- SQL Lesson 12: Order of execution of a Query
213
+
-- Find the number of movies each director has directed
214
+
SELECT director, Count(*)
215
+
FROM movies
216
+
Group by director;
217
+
218
+
-- Find the total domestic and international sales that can be attributed to each director
219
+
SELECT
220
+
m.director,
221
+
sum(b.domestic_sales+b.international_sales) as sum
222
+
FROM movies m
223
+
Join boxoffice b onb.movie_id=m.id
224
+
Group bym.director;
225
+
226
+
-- SQL Lesson 13: Inserting rows
227
+
-- Add the studio's new production, Toy Story 4 to the list of movies (you can use any director)
228
+
INSERT INTO movies
229
+
(id, title, director)
230
+
VALUES (15, 'Toy Story 4', 'John Lasseter');
231
+
232
+
-- Toy Story 4 has been released to critical acclaim! It had a rating of 8.7, and made 340 million domestically and 270 million internationally. Add the record to the BoxOffice table.
0 commit comments