2010-04-27 59 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;