Magento: Get customers ordered by order value

December 17th, 2012 by Richard Bairwell Leave a reply »

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

This post is over 6 months old.

This means that, despite my best intentions, it may no longer be accurate.

This blog holds over 12 years of archived content - during that time, I may have changed my opinion of something, technology will have advanced (and old "best standards" may no longer be the case), my technology "know how" has improved etc etc - it would probably take me a considerable amount of time to update all the archival entries: and defeat the point of keeping them anyway.

Please take these posts for what they are: a brief look into my past, my history, my journey and "caveat emptor".

Leave a Reply

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


gamy-dance