Specificationįor each of the following problems, you should write a single SQL query that outputs the results specified by each problem. The challenge ahead of you is to write SQL queries to answer a variety of different questions by selecting data from one or more of these tables.
#Imbd rating of all harry potter movies movie
(Only principal stars and directors are included.) Each table has just two columns: movie_id and person_id, which reference a specific movie and person, respectively. The rest of the row contains data about the rating for each movie and the number of votes the movie has received on IMDb.įinally, the stars and directors tables match people to the movies in which they acted or directed. The first column in the table is movie_id: a foreign key that references the id of the movies table. Movie ratings, meanwhile, are stored in the ratings table. The people table also has an id column, and also has columns for each person’s name and birth year. Notice that the movies table has an id column that uniquely identifies each movie, as well as columns for the title of a movie and the year in which the movie was released. By examining those statements, you can identify the columns present in each table. This will output the CREATE TABLE statements that were used to generate each of the tables in the database. In a terminal window, run sqlite3 movies.db so that you can begin executing queries on the database.įirst, when sqlite3 prompts you to provide a query, type. Provided to you is a file called movies.db, a SQLite database that stores data from IMDb about movies, the people who directed and starred in them, and their ratings. You should see a movies.db file, and some empty.
#Imbd rating of all harry potter movies how to
Here’s how to download this problem into your own CS50 IDE.
Write SQL queries to answer questions about a database of movies.