Database: movie_1

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: 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: Return all reviewer names and movie names together in a single list.
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: 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 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: 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 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: 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: 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 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 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