Skip to content

Instantly share code, notes, and snippets.

@egi
Forked from chartjes/gist:1370214
Created November 16, 2011 14:53
Show Gist options
  • Save egi/1370233 to your computer and use it in GitHub Desktop.
Save egi/1370233 to your computer and use it in GitHub Desktop.
Need help with a MySQL query
I have the following query:
SELECT COUNT( DISTINCT ( brand.id )), MONTH(u.created_at)
FROM brand
LEFT JOIN brand_admin_group bag ON brand.id = bag.brand_id
LEFT JOIN brand_admin_group_membership bagm ON bag.id = bagm.brand_admin_group_id
LEFT JOIN user u ON bagm.user_id = u.id
GROUP BY MONTH(u.created_at)
Results look like this:
23,"2011-01-04 16:55:51"
24,"2011-01-04 17:19:46"
25,"0000-00-00 00:00:00"
26,"2011-01-08 17:25:18"
27,"2011-01-08 22:34:55"
28,"2011-01-10 07:33:59"
29,"2011-01-12 08:06:30"
30,"2011-01-12 08:54:09"
31,"2011-01-12 09:12:20"
32,"2011-01-12 09:18:42"
33,"2011-01-12 09:19:58"
34,"2011-01-12 09:20:15"
Now, what I need to do is come up with a query that counts the number of brands grouped by the month of creation. u.created_at is a datetime field (ie 2011-02-08 19:13:58).
Any help would be appreciated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment