CREATE TABLE Movie (
    mID NUMBER PRIMARY KEY,
    title TEXT,
    year NUMBER,
    director TEXT
);
CREATE TABLE Reviewer (
    rID NUMBER PRIMARY KEY,
    name TEXT
);
CREATE TABLE Rating (
    rID NUMBER,
    mID NUMBER,
    stars NUMBER,
    ratingDate TIME,
    FOREIGN KEY ("rID") REFERENCES Reviewer("rID"),
    FOREIGN KEY ("mID") REFERENCES Movie("mID")
);

Question: Find the names of all reviewers who rated Gone with the Wind.
SQL: SELECT DISTINCT T3.name FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T2.title  =  'Gone with the Wind'

Question: What are the names of all the different reviewers who rates Gone with the Wind?
SQL: SELECT DISTINCT T3.name FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T2.title  =  'Gone with the Wind'

Question: Find the names of all directors whose movies are rated by Sarah Martinez.
SQL: SELECT DISTINCT T2.director FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T3.name  =  'Sarah Martinez'

Question: What are the names of all directors whose movies have been reviewed by Sarah Martinez?
SQL: SELECT DISTINCT T2.director FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T3.name  =  'Sarah Martinez'

Question: For any rating where the name of reviewer is the same as the director of the movie, return the reviewer name, movie title, and number of stars.
SQL: SELECT DISTINCT T3.name ,  T2.title ,  T1.stars FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T2.director  =  T3.name

Question: What are the different reviewer names, movie titles, and stars for every rating where the reviewer had the same name as the director?
SQL: SELECT DISTINCT T3.name ,  T2.title ,  T1.stars FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T2.director  =  T3.name

Question: Return all reviewer names and movie names together in a single list.
SQL: SELECT name FROM Reviewer UNION SELECT title FROM Movie

Question: What are the names of all the reviewers and movie names?
SQL: SELECT name FROM Reviewer UNION SELECT title FROM Movie

Question: Find the titles of all movies not reviewed by Chris Jackson.
SQL: SELECT DISTINCT title FROM Movie EXCEPT SELECT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T3.name  =  'Chris Jackson'

Question: What are the titles of all movies that were not reviewed by Chris Jackson?
SQL: SELECT DISTINCT title FROM Movie EXCEPT SELECT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID JOIN Reviewer AS T3 ON T1.rID  =  T3.rID WHERE T3.name  =  'Chris Jackson'

Question: For all directors who directed more than one movie, return the titles of all movies directed by them, along with the director name. Sort by director name, then movie title.
SQL: SELECT T1.title ,  T1.director FROM Movie AS T1 JOIN Movie AS T2 ON T1.director  =  T2.director WHERE T1.title != T2.title ORDER BY T1.director ,  T1.title

Question: For all directors who have directed more than one movie, what movies have they directed and what are their names?
SQL: SELECT T1.title ,  T1.director FROM Movie AS T1 JOIN Movie AS T2 ON T1.director  =  T2.director WHERE T1.title != T2.title ORDER BY T1.director ,  T1.title

Question: For directors who had more than one movie, return the titles and produced years of all movies directed by them.
SQL: SELECT T1.title ,  T1.year FROM Movie AS T1 JOIN Movie AS T2 ON T1.director  =  T2.director WHERE T1.title != T2.title

Question: For each director who directed more than one movie, what are the titles and dates of release for all those movies?
SQL: SELECT T1.title ,  T1.year FROM Movie AS T1 JOIN Movie AS T2 ON T1.director  =  T2.director WHERE T1.title != T2.title

Question: What are the names of the directors who made exactly one movie?
SQL: SELECT director FROM Movie GROUP BY director HAVING count(*)  =  1

Question: What are the names of all directors who made one movie?
SQL: SELECT director FROM Movie GROUP BY director HAVING count(*)  =  1

Question: What are the names of the directors who made exactly one movie excluding director NULL?
SQL: SELECT director FROM Movie WHERE director != "null" GROUP BY director HAVING count(*)  =  1

Question: What are the names of all directors who have made one movie except for the director named NULL?
SQL: SELECT director FROM Movie WHERE director != "null" GROUP BY director HAVING count(*)  =  1

Question: How many movie reviews does each director get?
SQL: SELECT count(*) ,  T1.director FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID  =  T2.mID GROUP BY T1.director

Question: For each director, how many reviews have they received?
SQL: SELECT count(*) ,  T1.director FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID  =  T2.mID GROUP BY T1.director

Question: Find the movies with the highest average rating. Return the movie titles and average rating.
SQL: SELECT T2.title ,  avg(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T1.mID ORDER BY avg(T1.stars) DESC LIMIT 1

Question: What are the movie titles with the highest average rating and what are those ratings?
SQL: SELECT T2.title ,  avg(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T1.mID ORDER BY avg(T1.stars) DESC LIMIT 1

Question: What are the movie titles and average rating of the movies with the lowest average rating?
SQL: SELECT T2.title ,  avg(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T1.mID ORDER BY avg(T1.stars) LIMIT 1

Question: What are the titles and average ratings for all movies that have the lowest average rating?
SQL: SELECT T2.title ,  avg(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T1.mID ORDER BY avg(T1.stars) LIMIT 1

Question: What are the names and years of the movies that has the top 3 highest rating star?
SQL: SELECT T2.title ,  T2.year FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID ORDER BY T1.stars DESC LIMIT 3

Question: What are the names and years released for the movies with the top 3 highest ratings?
SQL: SELECT T2.title ,  T2.year FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID ORDER BY T1.stars DESC LIMIT 3

Question: For each director, return the director's name together with the title of the movie they directed that received the highest rating among all of their movies, and the value of that rating. Ignore movies whose director is NULL.
SQL: SELECT T2.title ,  T1.stars ,  T2.director ,  max(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID WHERE director != "null" GROUP BY director

Question: For each director, what are the titles and ratings for all the movies they reviewed?
SQL: SELECT T2.title ,  T1.stars ,  T2.director ,  max(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID WHERE director != "null" GROUP BY director

Question: Find the title and star rating of the movie that got the least rating star for each reviewer.
SQL: SELECT T2.title ,  T1.rID ,  T1.stars ,  min(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T1.rID

Question: For each reviewer id, what is the title and rating for the movie with the smallest rating?
SQL: SELECT T2.title ,  T1.rID ,  T1.stars ,  min(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T1.rID

Question: Find the title and score of the movie with the lowest rating among all movies directed by each director.
SQL: SELECT T2.title ,  T1.stars ,  T2.director ,  min(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID  =  T2.mID GROUP BY T2.director