category: selecting single column
query: select title from films
category: selecting single column
query: select release_year from films
category: selecting single column
query: select name from people
category: selecting single column
query: select title from films
category: selecting multiple columns
query: select title, release_year from films
category: selecting multiple columns
query: select title, release_year, country from films
category: selecting multiple columns
query: select * from films
category: select distinct
query: select distinct country from films
category: select distinct
query: select distinct certification from films
category: select distinct
query: select distinct role from roles
category: learning to count
query: select count(*) from people
category: null and is null, count
query: select count(birthdate) from people where birthdate is not null
category: count, distinct
query: select count(distinct birthdate) from people
category: count, distinct
query: select count(distinct country) from films
category: selecting multiple columns, filtering results
query: select * from films where release_year = 2016
category: count, filtering results
query: select count(*) from films where release_year < 2000
category: filtering results, selecting multiple columns
query: select title, release_year from films where release_year > 2000
category: select multiple columns, filtering results
query: select * from films where language = 'French'
Quest: Get the name and birth date of the person born on November 11th, 1974. Remember to use ISO date format ('1974-11-11')!
category: selecting multiple columns, filtering resuls
query: select name, birthdate from people where birthdate = '1974-11-11'
category: count, filtering results
query: select count(*) from films where language = 'Hindi'
category: selecting multiple columns, filtering results
query: select * from films where certification = 'R'
category: filtering results, where AND, selecting multiple columns
query: select title, release_year from films where language = 'Spanish' and release_year < 2000
category: filtering results, where AND, selecting multiple columns
query: select * from films where language = 'Spanish' and release_year > 2000
category: selecting multple columns, filtering results, BETWEEN
query: select title, release_year from films where release_year between 1990 and 1999
category: selecting multiple columns, filtering results, BETWEEN
query: select title, release_year from films where release_year between 1990 and 2000
Quest: Get the title and release year of all films released in 1990 or 2000 that were longer than two hours. Remember, duration is in minutes!
category: selecting multiple columns, where or, where in
query: select title, release_year from films where release_year in (1990, 2000) and duration > 120
category: select single column, null and in null
query: select name from people where deathdate is null
category: count, null and is null
query: select count(*) from films where language is null
category: select single column, like and not like
query: select name from people where name like 'B%'
Quest: Get the names of people whose names have 'r' as the second letter. The pattern you need is '_r%'.
category: select single column, like and not like
query: select name from people where name like '_r%'
category : aggregate functions
query: select sum(duration) from films
category: aggregate functions
query: select max(duration) from films
category: aggregate functions
query: select avg(duration) from films
category: aggregate functions
query: select avg(gross) from films
Quest: Use the SUM function to get the total amount grossed by all films made in the year 2000 or later.
category: aggregate functions, filtering results
query: select sum(gross) from films where release_year >= 2000
category: aggregate functions, filtering results, like and not like
query: select avg(gross) from films where title like 'A%'
category: aggregate function, filtering results
query: select min(gross) from films where release_year = 1994
category: aggregate function, filtering results, BETWEEN
query: select max(gross) from films where release_year between 2000 and 2012
3
minus its budget) for all films. Alias the net profit as net_profit.
category: selecting multiple columns, alias (as), arithmetic
query: select title, (gross - budget) as net_profit from films
Quest: Get the title and duration in hours for all films. The duration is in minutes, so you'll need to divide by 60.0 to get the duration in hours. Alias the duration in hours as duration_hours.
category: selecting multiple columns, alias (as), arithmetic
query: select title, (duration / 60.0) as duration_hours from films
category: aggregate duration, arithmetic
query: select avg(duration / 60.0) from films
Quest: Get the percentage of people who are no longer alive. Alias the result as percentage_dead. Remember to use 100.0 and not 100!
category: count, arithmetic, multiple selects, null and is null, alias (as)
query: select (count() * 100.0 / (select count() from people)) as percentage_dead from people where deathdate is not null
Quest: Get the number of decades the films table covers. Alias the result as number_of_decades. The top half of your fraction should be enclosed in parentheses.
category: count, distinct, arithmetic, alias (as)
query: select count(distinct (release_year / 10)) as number_of_decades from films
category: order by, selecting single column
query: select name from people order by name
category: selecting single column, order by
query: select name from people order by birthdate
category: selecting multiple columns, order by
query: select birthdate, name from people order by birthdate
category: selecting single column, where in, filtering results, order by
query: select title from films where release_year in (2000, 2012) order by release_year
category: selecting multiple columns, filtering columns, order by
query: select * from films where release_year != 2015 order by duration
Quest: Get the title and gross earnings for movies which begin with the letter 'M' and order the results alphabetically.
category: selecting multiple columns, like and not like, order by
query: select title, gross from films where title like 'M%' order by title
Quest: Get the IMDB score and film ID for every film from the reviews table, sorted from highest to lowest score.
category: selecting multiple columns, order by (desc)
query: select imdb_score, film_id from reviews from reviews order by imdb_score desc
note : i used distinct function to detect if there is any non unique film_id in reviews meaning multiple reviews on same film so if it had became true then there would be a need to use foreign key with multiple select queries between films table and reviews table but i understood there is no need to do this here.
category: selecting multiple columns, order by (desc)
query: select title, duration form films order by duration desc
Quest: Get the birth date and name of people in the people table, in order of when they were born and alphabetically by name.
category: selecting multiple columns, order by (multiple)
query: select birthdate and name from people order by birthdate, name
Quest: Get certifications, release years, and titles of films ordered by certification (alphabetically) and release year.
category: selecting multiple columns, order by (multiple)
query: select certification, release_year, title from films order by certification, release_year
category: count, selecting multiple columns, group by
query: select release_year, count(*) films group by release_year
category: aggregate functions, selecting semi multiple columns, group by
query: select release_year, avg(duration) from films group by release_year
category: selecting semi multiple columns, group by, aggregate functions
query: select release_year, max(budget) from films group by release_year
category: selecting semi multiple columns, group by, aggregate functions
query: select language, sum(gross) from films group by language
Quest: Get the release year, country, and highest budget spent making a film for each year, for each country. Sort your results by release year and country.
category: selecting multiple columns, aggregate function, group by (multiple), order by (multiple)
query: select release_year, country, max(budget) from films group by release_year, country order by release_year, country
|
|
\ /
.
category: selecting multiple columns, aggregate function, group by (multiple), order by (multiple), having
query: select release_year, country, max(budget) from films group by release_year, country having (count(*) > 150) order by release_year, country
Quest: Get the country, average budget, and average gross take of countries that have made more than 10 films. Order the result by country name, and limit the number of results displayed to 5. You should alias the averages as avg_budget and avg_gross respectively.
category: selecting semi multiple columns, aggregate functions, group by, having, order by, count, limit, alias (as)
query: select country, avg(budget) as avg_budget, avg(gross) as avg_gross from films group by country having (count(*) > 10) order by country limit 5