AI Reports

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

  1. Go to Sales › Orders, add the Customer Group column; guests show as NOT LOGGED IN.
  2. 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

Related

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn