Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tegansnyder/5536310 to your computer and use it in GitHub Desktop.
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.
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