Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Created September 2, 2017 09:02
Show Gist options
  • Save Lewiscowles1986/d7c9a4195a67034b1d77fe67420b2b75 to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/d7c9a4195a67034b1d77fe67420b2b75 to your computer and use it in GitHub Desktop.
Nice monthly breakdown SQL
/*
* Uses MySQL SQL Syntax
*/
SELECT
YEAR(O.`when`) as `year`,
MONTH(O.`when`) as `month`,
COUNT(O.id) as `Orders Passed`, CONCAT('$',(COUNT(O.id) * 2)) as `earned`
FROM middleware.order_link O
GROUP BY `year`, `month`
UNION
SELECT
NULL as `year`,
NULL as `month`,
COUNT(O.id) as `Orders Passed`,
CONCAT('$',(COUNT(O.id) * 2)) as `earned`
FROM middleware.order_link O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment