MySQL Query GROUP BY day / month / year

前端 未结 14 2527
野趣味
野趣味 2020-11-22 06:37

Is it possible to make a simple query to count how many records I have in a determined period of time like a year, month, or day, having a TIMESTAMP field, like

14条回答
  •  萌比男神i
    2020-11-22 07:01

    I tried using the 'WHERE' statement above, I thought its correct since nobody corrected it but I was wrong; after some searches I found out that this is the right formula for the WHERE statement so the code becomes like this:

    SELECT COUNT(id)  
    FROM stats  
    WHERE YEAR(record_date) = 2009  
    GROUP BY MONTH(record_date)
    

提交回复
热议问题