MySQL_杭州11月销售昨日未上架的SKU_20161212

Posted Mr_Cxy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL_杭州11月销售昨日未上架的SKU_20161212相关的知识,希望对你有一定的参考价值。

#C034杭州11月销售昨日未上架的SKU

 

SELECT 城市,a.订单日期,a.客户数,a.订单数,b.产品数,a.金额,c.销售确认额,c.毛利额,c.毛利率
FROM (
	SELECT 城市,订单日期,COUNT(用户ID) AS 客户数,SUM(订单数) AS 订单数,SUM(金额) AS 金额
	FROM (
		SELECT 城市,订单日期,用户ID,COUNT(订单ID) AS 订单数,SUM(金额) AS 金额
		FROM (
			SELECT 城市,DATE(订单日期) AS 订单日期,用户ID,订单ID,SUM(金额) AS 金额
			FROM `a003_order` AS a1
			WHERE 城市=‘西安‘ AND 金额>0 AND 订单日期>=DATE_ADD(CURRENT_DATE,INTERVAL -15 DAY) AND 订单日期<CURRENT_DATE
			GROUP BY 订单ID
		) AS a2
		GROUP BY 订单日期,用户ID
	) AS a3
	GROUP BY 订单日期
) AS a
LEFT JOIN (#产品数
	SELECT 订单日期,COUNT(产品ID) AS 产品数,SUM(金额) AS 金额
	FROM (
		SELECT DATE(订单日期) AS 订单日期,产品ID,SUM(金额) AS 金额
		FROM `a003_order` 
		WHERE 城市=‘西安‘ AND 金额>0 AND 订单日期>=DATE_ADD(CURRENT_DATE,INTERVAL -15 DAY) AND 订单日期<CURRENT_DATE
		GROUP BY DATE(订单日期),产品ID
	) AS b1
	GROUP BY 订单日期
) AS b ON a.订单日期=b.订单日期
LEFT JOIN (#每天毛利
	SELECT DATE(应收日) AS 应收日,SUM(销售额) AS 销售确认额,SUM(毛利额) AS 毛利额,SUM(毛利额)/SUM(销售额) AS 毛利率
	FROM `a005_account`
	WHERE 城市=‘西安‘ AND 应收日>=DATE_ADD(CURRENT_DATE,INTERVAL -15 DAY) AND 应收日<CURRENT_DATE
	GROUP BY DATE(应收日)
) AS c ON a.订单日期=c.应收日

 

  

 

  

 

以上是关于MySQL_杭州11月销售昨日未上架的SKU_20161212的主要内容,如果未能解决你的问题,请参考以下文章

商城项目20_sku在es中储存模型分析索引建立上架逻辑核心上架流程图

MySQL_截止昨日南京市所有在职业务员业绩排名-20170116

MySQL_产品昨日库存与历史入库历史出库成本_20161124

MySQL学习_查看各仓库产品的销售情况_20161102

MySQL_杭州北仓 12.3-12.7需求活动期间累计下单达到3天及以上的客户_20161212

Inventory Reports