MySQL to get the count of rows that fall on a date for each day of a month

前端 未结 2 962
旧巷少年郎
旧巷少年郎 2021-01-03 06:43

I have a table that contains a list of community events with columns for the days the event starts and ends. If the end date is 0 then the event occurs only on the start da

2条回答
  •  情书的邮戳
    2021-01-03 07:10

    Try:

    SELECT COUNT(*), DATE(date) FROM table WHERE DATE(dtCreatedAt) >= DATE('2009-03-01') AND DATE(dtCreatedAt) <= DATE('2009-03-10') GROUP BY DATE(date);
    

    This would get the amount for each day in may 2009.

    UPDATED: Now works on a range of dates spanning months/years.

提交回复
热议问题