old question, but I found a great answer (not my own) using session variables.
Given a table
CREATE TABLE `report` ( `id` int(11) NOT NULL AUTO_INCREMENT, `reportDate` int(11) DEFAULT NULL, `count` int(11) DEFAULT NULL, `parameter` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `INDEX1` (`reportDate`,`parameter`,`count`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
The next query will select the top 10 options per day, depending on their number on that day.
SELECT parameter, reportDate, count FROM (SELECT parameter, reportDate, count, @reportDate_rank := IF(@current_reportDate = reportDate,@reportDate_rank + 1, 1) AS reportDate_rank, @current_reportDate := reportDate FROM report ORDER BY reportDate, count DESC ) dateRanked WHERE reportDate_rank <= 10;
source share