Skip to content
Introduction to SQL
  • AI Chat
  • Code
  • Report
  • Spinner

    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).

    Unknown integration
    DataFrameavailable as
    movie_info
    variable
    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
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.

    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, and num_votes in the reviews 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).

    🏃  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.

    Unknown integration
    DataFrameavailable as
    df
    variable
    SELECT film_id,imdb_score,num_votes FROM cinema.reviews
    where imdb_score >8 and num_votes>1000000
    
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.

    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 the country of origin in the films table.
    • Exclude NULL values in the budget column.
    • Order your results by the average budget in descending order.
    Unknown integration
    DataFrameavailable as
    df
    variable
    SELECT country,Avg(budget) as Avg_budget FROM cinema.films
    where budget is not null 
    group by country 
    order by Avg_budget Desc
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.

    4. Final Challenge!

    Now let's throw one final challenge your way. Update the sample query below to:

    • Return the language, total budget (aliased as total_budget), and total gross (aliased as total_gross) from the films 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.
    Unknown integration
    DataFrameavailable as
    df
    variable
    SELECT language,sum(budget) as total_budget,sum(gross) as Total_gross FROM cinema.films
    where duration >90
    and gross>1000000
    group by language
    
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.

    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!