sql 获取每位用户的总金额

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 获取每位用户的总金额相关的知识,希望对你有一定的参考价值。

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

以上是关于sql 获取每位用户的总金额的主要内容,如果未能解决你的问题,请参考以下文章