Skip to content

Instantly share code, notes, and snippets.

@rosiecakes
Created October 24, 2016 16:21
Show Gist options
  • Save rosiecakes/1855439e92e397e75c99ad54de28b290 to your computer and use it in GitHub Desktop.
Save rosiecakes/1855439e92e397e75c99ad54de28b290 to your computer and use it in GitHub Desktop.
sql exercises
DB: https://lagunita.stanford.edu/c4x/DB/SQL/asset/moviedata.html
For all cases where the same reviewer rated the same movie twice and gave it a higher rating the second time, return the reviewer's name and the title of the movie.
SELECT name, title
FROM movie, reviewer,
(SELECT rating1.rID, rating1.mID
FROM rating rating1, rating rating2
WHERE rating1.rID = rating2.rID
AND rating1.mID = rating2.mID
AND rating1.stars < rating2.stars
AND rating1.ratingDate < rating2.ratingDate) selection
WHERE movie.mID = selection.mID
AND reviewer.rID = selection.rID;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment