Created
May 7, 2013 21:30
-
-
Save tegansnyder/5536310 to your computer and use it in GitHub Desktop.
Get the the amount of money each customer has spent at your store along with all the skus of the products they have purchases in one SQL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT customer_id, customer_email, customer_firstname, customer_lastname, group_concat(si.sku SEPARATOR ',') as skus, SUM(subtotal_invoiced) AS cv | |
FROM sales_flat_order as so | |
INNER JOIN sales_flat_order_item AS si ON si.order_id = so.entity_id | |
GROUP BY customer_email | |
ORDER BY SUM(subtotal_invoiced) DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment