I am lost in MySQL documentation. I have a table with votes - it has these columns
- id
- song_id
- user_id
- created
I cannot find the query which will process the information and output the 10 most voted songs in a given time 开发者_Python百科period. What is it?
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;
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;
精彩评论