Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2016 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9bb66e835eea609265add51ae6daa64f to your computer and use it in GitHub Desktop.
Save anonymous/9bb66e835eea609265add51ae6daa64f to your computer and use it in GitHub Desktop.
SELECT * FROM (select date_format(now() - INTERVAL 12 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 11 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 10 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 9 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 8 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 7 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 6 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 5 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 4 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 3 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 2 MONTH,'%Y-%m') as month UNION select date_format(now() - INTERVAL 1 MONTH,'%Y-%m') as month) AS `t1` NATURAL LEFT JOIN (SELECT * FROM (SELECT date_format(`sent_at`, '%Y-%m') AS `month`, count(`job_mails`.`id`) AS `count` FROM `job_mails` WHERE (`sent_at` IS NOT NULL) GROUP BY `month`) AS `t1`) AS `t2`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment