Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. SELECT
  2. o.name, AVG(r.rating) AS cnt
  3. FROM
  4. ratings r
  5. JOIN
  6. genres_movies g ON r.movie_id = g.movie_id
  7. JOIN
  8. users u ON r.user_id = u.id
  9. JOIN
  10. occupations o ON u.occupation_id = o.id
  11. WHERE
  12. g.id = 11
  13. AND o.name IN (SELECT
  14. o.name
  15. FROM
  16. ratings r
  17. JOIN
  18. users u ON r.user_id = u.id
  19. JOIN
  20. occupations o ON u.occupation_id = o.id
  21. GROUP BY o.name
  22. HAVING COUNT(r.user_id) > 3)
  23. GROUP BY u.occupation_id
  24. ORDER BY cnt DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement