Tutorial SLQ Bolt
Tutorial SLQ Bolt
-- Find the movies released in the years between 2000 and 2010
SELECT *
FROM Movies
WHERE Year BETWEEN 2000 AND 2010;
-- Find the movies not released in the years between 2000 and 2010
SELECT *
FROM Movies
WHERE Year NOT BETWEEN 2000 AND 2010;
-- Find all the movies (and director) not directed by John Lasseter
SELECT *
FROM Movies
WHERE Director != "John Lasseter";
-- List the last four Pixar movies released (ordered from most recent to least)
SELECT *
FROM Movies
ORDER BY Year DESC
LIMIT 4;
-- Order all the cities in the United States by their latitude from north to south
SELECT *
FROM North_american_cities
WHERE Country = "United States"
ORDER BY Latitude DESC;
-- List all the cities west of Chicago, ordered from west to east
SELECT *
FROM North_american_cities
WHERE Longitude < -87.69
ORDER BY Longitude ASC;
-- Show the sales numbers for each movie that did better internationally rather
than domestically
SELECT Title, International_sales, Domestic_sales
FROM Movies JOIN Boxoffice
ON Id=Movie_id
WHERE International_sales > Domestic_sales;
-- 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 name and role of all employees who have not been assigned to a building
SELECT *
FROM Employees
LEFT JOIN Buildings
ON Building_name = Building
WHERE Building IS NULL;
-- Find the longest time that an employee has been at the studio
SELECT MAX(Years_employed)
FROM Employees;
-- For each role, find the average number of years employed by employees in that
role
SELECT Role, AVG(Years_Employed)
FROM Employees
GROUP BY Role;
-- Find the total domestic and international sales that can be attributed to each
director
SELECT Director, sum(Domestic_sales + International_Sales) as Total_Sales
FROM Movies
LEFT JOIN Boxoffice ON Id = Movie_ID
GROUP BY Director;
-- Add the studio's new production, Toy Story 4 to the list of movies (you can use
any director)
INSERT INTO Movies,
VALUES (4, "Toy Story 4", "John Lasseter", 2017, 123);
-- 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.
INSERT INTO Boxoffice
VALUES (4, 8.7, 340000000, 270000000);
-- The director for A Bug's Life is incorrect, it was actually directed by John
Lasseter
UPDATE Movies
SET Director = "John Lasseter"
WHERE Id = 2;
-- The year that Toy Story 2 was released is incorrect, it was actually released in
1999
UPDATE Movies
SET Year = "1999"
WHERE Id = 3;
-- Both the title and directory for Toy Story 8 is incorrect! The title should be
"Toy Story 3" and it was directed by Lee Unkrich
UPDATE Movies
SET Title = "Toy Story 3", Director = "Lee Unkrich"
WHERE Id = 11;
-- This database is getting too big, lets remove all movies that were released
before 2005.
DELETE FROM Movies
WHERE Year < 2005;
-- Andrew Stanton has also left the studio, so please remove all movies directed by
him.
DELETE FROM Movies
WHERE Director = "Andrew Stanton";
-- Add a column named Aspect_ratio with a FLOAT data type to store the aspect-ratio
each movie was released in.
ALTER TABLE Movies
ADD COLUMN Aspect_ratio FLOAT DEFAULT 3;
-- Add another column named Language with a TEXT data type to store the language
that the movie was released in. Ensure that the default for this language is
English.
ALTER TABLE Movies
ADD COLUMN Language TEXT DEFAULT "English";
-- We've sadly reached the end of our lessons, lets clean up by removing the Movies
table
DROP TABLE Movies;