MySQL – report on sales by month for a given time period

Here’s a nice sql script to get a report of monthly orders and sales for a time period.

SELECT
 YEAR(DATETIME) AS `year`,
 MONTHNAME(DATETIME) AS `month`,
 SUM(subtotal) AS `subtotal`,
 count(*) AS orders
FROM orders
WHERE DATETIME BETWEEN '2014-04-01' AND '2014-07-01'
GROUP BY YEAR(DATETIME), MONTH(DATETIME)

mysql report sales