Magento 2 SQL queries › Orders and sales
How many orders did we receive last month, by status?
Short answer: Filter the order grid by purchase date and status, one status at a time, or run one query that groups last month's orders by status.
In the Magento admin
- Go to Sales › Orders and open Filters.
- Set Purchase Date to the first and last day of last month.
- Pick one Status at a time and note the record count above the grid.
With one query
These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.
Works on Magento Open Source and Adobe Commerce:
SELECT o.status, COUNT(*) AS orders, ROUND(SUM(o.base_grand_total), 2) AS base_total
FROM sales_order o
WHERE o.created_at >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y-%m-01')
AND o.created_at < DATE_FORMAT(CURRENT_DATE, '%Y-%m-01')
GROUP BY o.status
ORDER BY orders DESC;
Good to know
created_atis stored in UTC, so orders placed late on the last evening of the month can land in the next month in your local time.statusis the label your store shows (for example processing or complete);stateis Magento's fixed workflow step behind it. Custom statuses all map to one state.