Magento: Get customers ordered by order value

Want to know which of your Magento e-commerce shopping cart customers have ordered the most this year? Well, I’ve written the following SQL query to help:

SELECT SUM(sales_flat_order.base_total_invoiced) AS totalvalue,sales_flat_order.customer_firstname,sales_flat_order.customer_lastname,sales_flat_order.customer_email,sales_flat_order_address.street,sales_flat_order_address.city,sales_flat_order_address.region,sales_flat_order_address.postcode FROM sales_flat_order,sales_flat_order_address WHERE sales_flat_order.state='complete' AND sales_flat_order.created_at>'2012-01-01' AND sales_flat_order_address.entity_id=sales_flat_order.billing_address_id GROUP BY sales_flat_order.customer_email ORDER BY totalvalue DESC

Leave a Reply