Reputation: 1247
I am lost in MySQL documentation. I have a table with votes - it has these columns
I cannot find the query which will process the information and output the 10 most voted songs in a given time period. What is it?
Upvotes: 0
Views: 71
Reputation: 181
How exactly are you storing the votes? Replace the words in [] below with the variables you want.
select song_id
from [table]
where created > to_date('[the date you want]', '[the format you want]') and created < to_date('[the date you want]', '[the format you want]')
order by [votes]
limit 10;
Upvotes: 0
Reputation: 43467
SELECT id, song_id, COUNT(1) AS total
FROM votes
WHERE created BETWEEN [user_defined_start_date] AND [user_defined_end_date]
GROUP BY song_id
ORDER BY total DESC
LIMIT 10;
Upvotes: 4