MySQL查询建议

时间:2010-04-27 20:26:04

标签: sql mysql

我迷失在MySQL文档中。我有一张投票表 - 它有这些列

  • ID
  • song_id
  • USER_ID
  • 创建

我无法找到将处理信息并在给定时间段内输出10首投票最多的歌曲的查询。它是什么?

2 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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;