AI Reports

Magento 2 SQL queries › Store setup

Which customer groups exist, and how many customers are in each?

Short answer: Customers › Customer Groups lists the groups; the query adds how many customers each has.

In the Magento admin

  1. Go to Customers › All Customers and filter by Group, one at a time.

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 g.customer_group_id, g.customer_group_code, COUNT(c.entity_id) AS customers
FROM customer_group g
LEFT JOIN customer_entity c ON c.group_id = g.customer_group_id
GROUP BY g.customer_group_id, g.customer_group_code
ORDER BY g.customer_group_id;

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