我迷失在MySQL文档中。我有一张投票表 - 它有这些列
我无法找到将处理信息并在给定时间段内输出10首投票最多的歌曲的查询。它是什么?
答案 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;