Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. SELECT rec.title AS title,
  2. count(distinct keywords.keyword)
  3. + 10 * count(distinct people.id)
  4. AS score
  5.  
  6. FROM movies AS rec
  7. JOIN credits ON rec.id = credits.movie_id AND credits.type = 'actor'
  8. JOIN people ON people.id = credits.person_id
  9.  
  10. JOIN keywords ON keywords.movie_id = rec.id
  11.  
  12. WHERE keywords.keyword IN(
  13. SELECT keywords.keyword
  14. FROM keywords
  15. JOIN movies ON movies.id = keywords.movie_id
  16. WHERE movies.title = 'Skyfall (2012)')
  17.  
  18. AND people.id IN (
  19. SELECT people.id
  20. FROM people
  21. JOIN credits ON credits.person_id = people.id AND credits.type = 'actor'
  22. JOIN movies ON credits.movie_id = movies.id
  23. WHERE movies.title = 'Skyfall (2012)'
  24. )
  25. AND count(distinct keywords.keyword) > 0
  26. AND count(distinct people.id) > 0
  27.  
  28. GROUP BY rec.title
  29. ORDER BY score DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement