Top 20 Customers

BigCommerce

 

BigCommerce is the leading e-commerce platform for running an online store.

Top 20 customers (as measured by dollars spent) for the selected date

Query Text

SELECT 
    Orders_Customers."FirstName" ||' ' || Orders_Customers."LastName" 'Customer Name',
    Orders_Customers."Email",
    COUNT(*) AS "Orders count",
    SUM(Orders."TotalIncTax") AS "Amount Spent"
FROM 
    "Orders"
LEFT OUTER JOIN
    "Customers" AS Orders_Customers ON "Orders"."CustomerId" = Orders_Customers."id"
WHERE
    (Orders."StatusId" != 4 AND Orders."StatusId" != 5) and strftime('%Y', Orders."DateCreated")='2016'
GROUP BY
    'Customer Name', Orders_Customers."Email"
ORDER BY
    SUM(Orders."TotalIncTax") desc
LIMIT 20
  

Open Query