How to create a SQL query that would go to the table and count the number of records by month. Well, that is, there are entries in the table: id - 1, name - test, date - 2014-01-01; id - 2, name - test2, date - 2014-02-01; You need to count the number of records by month and update the number in another table in which the structure Month is a number. Here are the images of the first table from which to calculate

Imgur

the second table where you need to update the number

Imgur

    2 answers 2

    SELECT MONTHNAME(date),COUNT(*) FROM table1 GROUP BY MONTHNAME(date) 

    you will understand with an insert

      in the second table you need to make the month ID 01,02,03,04 .., 12 do

       BETWEEN year(now())+'-'tble2.id_month+'-'+01 AND year(now())+'-'tble2.id_month+'-'+31 

      Well, what to do next, I think you will understand!