Magento 2 SQL queries › Orders and sales
What share of orders came from guests and what share from registered customers?
Short answer: Every order records whether the customer was a guest. Count them and divide.
In the Magento admin
- Go to Sales › Orders, add the Customer Group column; guests show as NOT LOGGED IN.
- Export and count the two groups in a spreadsheet.
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 IF(o.customer_is_guest = 1 OR o.customer_id IS NULL, 'Guest', 'Registered') AS buyer,
COUNT(*) AS orders,
ROUND(100 * COUNT(*) / SUM(COUNT(*)) OVER (), 1) AS share_pct,
ROUND(SUM(o.base_grand_total), 2) AS revenue
FROM sales_order o
WHERE o.state <> 'canceled'
AND o.created_at >= CURRENT_DATE - INTERVAL 12 MONTH
GROUP BY buyer;
Good to know
- Uses a window function, which needs MySQL 8 or MariaDB 10.2 or newer (every supported Magento 2.4 database has it).
- A guest who later registers keeps their old orders as guest orders.