Magento 2 SQL queries: everyday questions
Answers to the questions Magento store teams ask every day: orders, customers, products, stock, prices and store setup. Each page shows where to look in the admin and a query for your developer, tested on Magento Open Source and Adobe Commerce 2.4.
Orders and sales
- How many orders did we receive last month, by status?
- What was our revenue per website last month, excluding canceled orders?
- What's our average order value per month this year?
- Which payment methods were used last month, and how many orders each?
- Which shipping methods do customers choose most?
- Which orders are still pending after 3 days?
- Which paid orders haven't shipped after 3 days?
- Which countries did our orders come from last quarter?
- How many orders used a coupon code last month, and which codes?
- Compare orders this October with October last year, per website.
- What share of orders came from guests and what share from registered customers?
Customers
- How many customers registered this month, per customer group?
- Who are our top 20 customers by total spend this year?
- How many customers placed more than one order this year?
- How many customer accounts have never placed an order?
- Which customer group has the highest average order value?
- How many newsletter subscribers do we have?
- Which cities do our repeat customers come from?
Products and catalogue
- Which enabled products aren't in any category?
- Which products have a price of 0?
- Which products are enabled by default but disabled in a store view?
- How many products are in each attribute set?
- Which products have no description?
- Which products were added in the last 30 days?
- What values does the color attribute have, and how many products use each?
- Which configurable products have no variant in stock?
- Which products still have a special price whose end date has passed?
Stock
- Which products have fewer than 5 units in stock?
- What's the total stock quantity in each source?
- Which products allow backorders?
- Which products have never sold?
- Which in-stock products haven't sold in 90 days?
Prices and promotions
- Which cart price rules are active right now?
- How many times has each coupon code been used?
- Which catalog price rules apply to the Wholesale customer group?
- How much discount did we give in total last month?
- Which products have tier prices?
- How many orders had free shipping last month?
Store setup
- List all websites and store views with their codes.
- Which customer groups exist, and how many customers are in each?
- Which root category does each store use?
- How many active CMS pages does each store view have?
- Which attributes are used as filters on category pages?