user_id | created_at
1 | 123456
1 | 123456
2 | 123456
2 | 123456
3 | 123456
3 | 123456
3 | 123456
3 | 123456
user_id | count | month
1 | 2 | 12
2 | 2 | 5
3 | 4 | 3
SELECT
user_id,
COUNT(1) as count,
MONTH(FROM_UNIXTIME(created_at)) as month
FROM
my_table
GROUP BY
user_id,
MONTH(FROM_UNIXTIME(created_at))