Created
December 16, 2015 15:05
-
-
Save davidsommer/871bc8e74c3ef0779df2 to your computer and use it in GitHub Desktop.
Get Total Amount per User
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, order_cnt, totalBestellwertUser | |
FROM ( | |
SELECT customer_id, | |
COUNT(customer_id) AS order_cnt, | |
SUM(totalBestellwert) AS totalBestellwertUser | |
FROM (SELECT so.customer_id, | |
YEAR(so.created_at) AS year_ordered, | |
SUM(base_grand_total) AS totalBestellwert, | |
group_concat(si.sku SEPARATOR ',') AS skus | |
FROM `sales_flat_order` AS so | |
INNER JOIN `sales_flat_order_item` AS si ON si.order_id=so.entity_id | |
WHERE so.customer_id IS NOT NULL | |
GROUP BY entity_id | |
) sub_query | |
GROUP BY customer_id | |
) main_sub_query |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment