How to group by year and month in My SQL

Ask a question+

I have a table user_games with a date field created_at. So I’m trying to group records by given year and month and find the number of records. I use MySQL. So this is my query. It seems it’s working, but I am not sure that it is the correct way

SELECT concat(year(ug.created_at), '-' ,month(ug.created_at)), ug.user_id, count(*)
FROM user_games ug
GROUP BY concat(year(ug.start_date), '-' ,month(ug.start_date));

Is there better approche ?

add comment

0 Answer

Your Answer