67 | | |
| 67 | select title from( |
| 68 | select m.title, sum(mv.stars_rated) as total |
| 69 | from replies r |
| 70 | join discussions d on r.discussion_id = d.discussion_id |
| 71 | join replies r2 on r2.discussion_id = d.discussion_id and r2.user_id != 1 |
| 72 | join users u on u.user_id = r2.user_id and |
| 73 | |
| 74 | ( |
| 75 | select count(r3.reply_id) |
| 76 | from replies r3 |
| 77 | group by u.user_id |
| 78 | ) >= |
| 79 | ( |
| 80 | |
| 81 | select count(*)::float / (select count(*)::float from users) |
| 82 | from replies |
| 83 | ) |
| 84 | |
| 85 | join movie_rates mv on mv.user_id = u.user_id |
| 86 | join movies m on m.movie_id = mv.movie_id |
| 87 | where r.user_id = 1 and |
| 88 | r.date between current_date - interval '2 months' and current_date |
| 89 | group by m.title |
| 90 | order by sum(mv.stars_rated) desc |
| 91 | limit 15 |
| 92 | ) as tabela; |