Introduction to SQL
👋 Welcome to your new workspace! Here, you can experiment with the movie data you used in Introduction to SQL and practice your newly learned skills with some challenges. You can find out more about DataCamp Workspace here.
This workspace takes about 20 minutes to complete, but you are free to experiment as long as you like!
1. Get Started
Below is a SQL cell. It is used to execute SQL queries. There is already a pre-written query to get you started that accesses film and box office performance information for the top 10 Hollywood movies by IMDB score.
You can click the "Browse tables" button in the upper righthand corner of the cell below to view the available tables.
Note: The databases from three different courses are available, which you can preview using the dropdown menu to the left. To access the cinema
data, you will need to add this schema name to every table that you query (e.g., cinema.films
for the films
table, and cinema.reviews
for the reviews
table).
SELECT title, release_year, budget, gross, imdb_score FROM cinema.films
INNER JOIN cinema.reviews
ON cinema.films.id = cinema.reviews.film_id
WHERE num_votes > 10000
AND country = 'USA'
AND budget IS NOT NULL
AND gross IS NOT NULL
AND certification IN ('PG', 'PG-13', 'R')
ORDER BY imdb_score DESC
LIMIT 10
2. Your Turn
Now it's your turn to try out some challenge queries using the cells below. To start, update the sample query below to:
- Select the
film_id
,imdb_score
, andnum_votes
in thereviews
table. - Filter your results for records where:
- The
imdb_score
is greater than 8. - The number of votes (
num_votes
) is more than 1 million (1000000).
- The
🏃 To execute a query, click inside the cell to select it and click "Run" or the ► icon. You can also use Shift-Enter to run a selected cell and automatically navigate to the next cell.
SELECT * FROM cinema.reviews
LIMIT 5
3. Keep going!
Continue to flex your SQL skills and update the sample query below to:
- Return the average cost to make a movie (
budget
) by thecountry
of origin in thefilms
table. - Exclude
NULL
values in thebudget
column. - Order your results by the average budget in descending order.
SELECT * FROM cinema.films
LIMIT 5
4. Final Challenge!
Now let's throw one final challenge your way. Update the sample query below to:
- Return the
language
, totalbudget
(aliased astotal_budget
), and totalgross
(aliased astotal_gross
) from thefilms
table. - Filter the records for films with a duration greater than 90.
- Only include languages where the total gross is over 1 million (1000000).
- Order your results by the total gross in descending order.
SELECT * FROM cinema.films
LIMIT 5
5. Next Steps
Feel free to continue to experiment with these tables by creating a new SQL cell below, or if you're interested in more, try the following options:
- Create a new blank workspace and connect to our sample integrations to further refine your SQL skills!
- Check out Joining Data in SQL. This course will teach you how to join different tables together using such techniques as inner joins, outer joins, and more!