You simple need to run a COUNT
query and GROUP
the results by month and possibly year:
SELECT YEAR(sentence_start) AS Y, MONTH(sentence_start) AS M, COUNT(*) AS C
FROM prisoner
GROUP BY YEAR(sentence_start), MONTH(sentence_start)
It is also possible to use the MySQL EXTRACT
function to obtain same results MUCH faster:
SELECT EXTRACT(YEAR_MONTH FROM sentence_start) AS YM, COUNT(*) AS C
FROM prisoner
GROUP BY EXTRACT(YEAR_MONTH FROM sentence_start)