I need to print for each year: the title of the movie, year and rank-in-year of top 5 clips, based on their ranking.
So, i need to find the top 5 rated movies of each year. I've tried a GROUP BY year(releases.date) but i also need the titles and i need to get N-th top rows of each group.
CLIPS [ id, title ]
RELEASES [ id_clip, date ]
RANKS [ id_clip, nr_votes, ranking ]
Any hints ? I am using MySQL. I also have the year in the clips table.
mysql> select * from clip LIMIT 5;
+--------+-----------------------+------+-----------+
| idclip | title | year | clip_type |
+--------+-----------------------+------+-----------+
| 4 | !Women Art Revolution | 2010 | 0 |
| 7 | #1 | 2005 | 0 |
| 8 | #1 (I) | 2010 | 2 |
| 9 | #1 (II) | 2010 | 2 |
| 12 | #1 Cheerleader Camp | 2010 | 2 |
+--------+-----------------------+------
mysql> select * from releasedates LIMIT 5;
+---------+---------------------+---------+
| id_clip | date | country |
+---------+---------------------+---------+
| 4 | 2010-09-01 00:00:00 | Canada |
| 1773811 | 2006-01-22 00:00:00 | USA |
| 1773815 | 2006-02-12 00:00:00 | USA |
| 1773818 | 2006-02-19 00:00:00 | USA |
| 1773820 | 2006-01-22 00:00:00 | USA |
+---------+---------------------+---------+
5 rows in set (0,00 sec)
mysql> select * from ratings LIMIT 5;
+---------+-------+---------+
| id_clip | votes | ranking |
+---------+-------+---------+
| 4 | 8 | 8.0 |
| 1773811 | 51 | 4.5 |
| 1773839 | 753 | 6.3 |
| 1773843 | 32 | 6.9 |
| 1773844 | 18 | 7.1 |
+---------+-------+---------+
5 rows in set (0,00 sec)