import sqlite3
con = sqlite3.connect('movie_db.db')# connect to a database (or create it, if it doesn't already exist)
cur = con.cursor()#generate a 'live' cursor
with open("movie_db.sql") as f:
sql_data = f.read()
#print(sql_data[0:400],10)
cur.executescript(sql_data);
import pandas
pandas.set_option('display.max_rows',20)
def sql_request(q):
cur.execute(q)
return pandas.DataFrame(cur.fetchall(),columns=[d[0] for d in cur.description]) # just using Pandas for nice tabular display of results, nothing more
Study this jupyter notebook and ...
* [5pts] Answer the 5 extended questions
* [5pts] Answer 5 additional questions from the list of 15 more questions. (You can pick any 5.)
LastName_FirstName_HW3.ipynb
Your answer for each question should be in the form of indicated in the notebook. For example, if the question is:
1. Write a query that returns movies released after 2012.
Then any query invoking 'year>2012' would be correct, such as the following:
query1 = "select * from movie,rating,reviewer on (movie.movieID=rating.movieID and rating.raterID=reviewer.raterID and year>2012)"
sql_request(query1)
This returns movies and their reviews, and does not include movies that were not reviewed.
query1 = "select * from movie where movie.year>2012"
sql_request(query1)
This is all movies more recent than 2012, including those that do and don't have reviews.