SQL => https://sqlbolt.com/
SELECT Title
FROM movies;
SELECT director
FROM movies;
SELECT director,title
FROM movies;
SELECT year ,title
FROM movies;
SELECT *
FROM movies;
SELECT *
FROM movies
WHERE ID=6;
SELECT *
FROM movies
WHERE Year BETWEEN 2000 AND 2010;
SELECT *
FROM movies
WHERE Year NOT BETWEEN 2000 AND 2010;
SELECT *
FROM movies
LIMIT 5;
SELECT *
FROM movies
WHERE Title like "%toy Story%";
SELECT *
FROM movies
WHERE Director like "%John Lasseter%";
SELECT *
FROM movies
WHERE Director not like "%John Lasseter%";
SELECT *
FROM movies
WHERE Title like "%WALL-%";
SELECT DISTINCT Director
FROM movies
ORDER BY Director;
SELECT *
FROM movies
ORDER BY Year desc
limit 4;
SELECT *
FROM movies
order by Title
limit 5 ;
SELECT *
FROM movies
order by Title
limit 5 offset 5 ;
SELECT *
FROM north_american_cities
where country = "Canada";
SELECT *
FROM north_american_cities
WHERE Country like "%United States%"
order by latitude desc ;
SELECT City
FROM north_american_cities
WHERE Longitude <-87.629798
order by Longitude ;
SELECT *
FROM north_american_cities
WHERE Country LIKE "%Mexico%"
order by Population desc
limit 2 ;
-- List the third and fourth largest cities (by population) in the United States and their population
SELECT city
FROM north_american_cities
WHERE Country like "%United States%"
order by Population desc
limit 2 offset 2 ;
SELECT title,Domestic_sales,International_sales
FROM movies
join Boxoffice on Id=Movie_id ;
SELECT title,Domestic_sales,International_sales
FROM movies
join Boxoffice on Id=Movie_id
where Domestic_sales<International_sales;
SELECT title,rating
FROM movies
join Boxoffice on Id=Movie_id
order by Rating desc;
SELECT DISTINCT Building
FROM employees
join Buildings on Building=Building_name
where Years_employed >0;
SELECT *
FROM Buildings ;
SELECT DISTINCT Building_NAME,Role
FROM Buildings
LEFT JOIN Employees ON Building_name=Building ;
SELECT *
FROM employees
WHERE Building IS NULL;
SELECT *
FROM Buildings
LEFT JOIN Employees
ON Building_name = Building
WHERE Building IS NULL;
SELECT title,(Domestic_sales+International_sales)/1000000 AS TOTAL_SALES
FROM movies
join Boxoffice on Id=Movie_id ;
SELECT title,(10*Rating) AS Rating_percentage
FROM movies
join Boxoffice on Id=Movie_id ;
SELECT title,(year%2) AS EVEN_YEAR
FROM movies
where EVEN_YEAR =0 ;
SELECT max(Years_employed)
FROM employees;
SELECT AVG(Years_employed),ROLE
FROM employees GROUP BY ROLE;
SELECT SUM(Years_employed),Building
FROM employees GROUP BY Building;
SELECT role,count()
FROM employees
where role="Artist";
SELECT role,count(*) AS no_artist
from employees group by role;
SELECT *,role,sum(Years_employed)
FROM employees
where role like "%Engineer%";
SELECT Director,count()
FROM movies group by Director;
SELECT Director,sum(Domestic_sales+International_sales)
FROM movies
JOIN Boxoffice
ON Id=Movie_id
GROUP BY 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)
UPDATE Movies
SET Director="John Lasseter"
WHERE Title ="A Bug's Life";
UPDATE Movies
SET Year=1999
WHERE Title ="Toy Story 2";
-- Both the title and director 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 Title ="Toy Story 8";
DELETE FROM Movies
WHERE Year<2005;
DELETE FROM Movies
WHERE Director="Andrew Stanton";
CREATE TABLE Database (
Name TEXT,
Version FLOAT,
Download_count INTEGER);
-- 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 Aspect_ratio FLOAT DEFAULT 1 ;
-- 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 Language TEXT DEFAULT English ;
DROP TABLE Movies;
DROP TABLE BoxOffice;