I’m having trouble on generating a report in MySQL. I have this table:
CREATE TABLE users (
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
birthday DATE,
title VARCHAR(255)
);
I need to generate a report that throws how many titles exist for a given month. My first idea was something like this:
SELECT COUNT(DISTINCT(MONTH(birthday))) AS q
FROM users
Of course that only returns how many months exist in the records. What I need is something like this:
Month | Count ------------- 2 | 384 5 | 131 12 | 585
This should work:
This will give you the month number and the count of the records in that month, thus what you are looking for.