我有以下MySQL表名为“proposal”:
用户每个月都会提出书籍,因此每月会有50-100本书。我想知道是否有一种编写查询的方法可以返回给定月份的最多建议书籍。
提前致谢。
答案 0 :(得分:4)
SELECT proposal_book, COUNT(*) AS cnt
FROM proposals
WHERE proposal_date >= $first_day_of_month
AND proposal_date < $first_day_of_month + INTERVAL 1 MONTH
GROUP BY
proposal_book
ORDER BY
cnt DESC
LIMIT 10
答案 1 :(得分:0)
SELECT * FROM proposals GROUP BY proposal_book ORDER BY COUNT(proposal_id) DESC