2010-04-27 60 views
0

我迷失在MySQL文档中。我有票表 - 它有这些列MySQL查询建议

  • ID
  • song_id
  • user_id说明
  • 创建

我找不到将处理信息和输出的查询10在特定时间段内最受欢迎的歌曲。它是什么?

回答

4
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; 
0

您究竟如何存储投票? 将下面[]中的单词替换为所需的变量。

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;