tags:

views:

40

answers:

2

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 period. What is it?

+4  A: 
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;
cballou
A: 

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;
leadingzero