50 | | |
51 | | select distinct m.title |
52 | | from replies r |
53 | | join discussions d on r.discussion_id = d.discussion_id |
54 | | join replies r2 on r2.discussion_id = d.discussion_id and r2.user_id != 1 |
55 | | join users u on u.user_id = r2.user_id |
56 | | join movie_likes ml on ml.user_id = u.user_id |
57 | | join movies m on m.movie_id = ml.movie_id |
58 | | where r.user_id = 1; |
| 50 | select title from( |
| 51 | select m.title, sum(mv.stars_rated) as total |
| 52 | from replies r |
| 53 | join discussions d on r.discussion_id = d.discussion_id |
| 54 | join replies r2 on r2.discussion_id = d.discussion_id and r2.user_id != 1 |
| 55 | join users u on u.user_id = r2.user_id |
| 56 | join movie_rates mv on mv.user_id = u.user_id |
| 57 | join movies m on m.movie_id = mv.movie_id |
| 58 | where r.user_id = 1 |
| 59 | group by m.title |
| 60 | order by sum(mv.stars_rated) desc |
| 61 | limit 10 |
| 62 | ) as tabela; |