MySQL query to return most of the offered books in a month

I have the following MySQL table named "clauses":

  • proposal_id
  • offer_user (int
  • book_clause (int)
  • offer_date (Ymd)

Users are going to offer books every month, so there will be 50-100 books per month. I would like to know if there is a way to write a query that can return the most suggested books for a given month.

Thanks in advance.

+2


a source to share


2 answers


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

      



+4


a source


SELECT * FROM proposals GROUP BY proposal_book ORDER BY COUNT(proposal_id) DESC

      



0


a source