Think Summer: Day 1 Notes — 2022

Loading the database

%sql sqlite:////anvil/projects/tdm/data/movies_and_tv/imdb.db

Extracting a few rows from the each of the 6 tables

%%sql
SELECT * FROM titles LIMIT 5;
%%sql
SELECT * FROM episodes LIMIT 5;
%%sql
SELECT * FROM people LIMIT 5;
%%sql
SELECT * FROM ratings LIMIT 5;
%%sql
SELECT * FROM crew LIMIT 5;
%%sql
SELECT * FROM akas LIMIT 5;

We can see how many rows were in each table, as follows:

%%sql
SELECT COUNT(*) FROM titles LIMIT 5;
%%sql
SELECT COUNT(*) FROM episodes LIMIT 5;
%%sql
SELECT COUNT(*) FROM people LIMIT 5;

We can also start to investigate individual people, for instance:

%%sql
SELECT * FROM people WHERE name = 'Ryan Reynolds' LIMIT 5;
%%sql
SELECT * FROM people WHERE name = 'Hayden Christensen' LIMIT 5;

Friends is one of Dr Ward’s favorite shows. We can find it here:

%%sql
SELECT * FROM titles WHERE (primary_title = 'Friends') AND (premiered > 1992) LIMIT 5;

We can investigate how many titles premiered in each year, by grouping things together according to the year that the title premiered, and by ordering the results according to the year that the title premiered. The "desc" specifies that we want the results in descending order, i.e., with the largest result first (where "largest" means the "last year", because we are ordering by the years).

%%sql
SELECT COUNT(*), premiered FROM titles
GROUP BY premiered ORDER BY premiered DESC LIMIT 20;