码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-12-12 23:02:39      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:blog   color   上架   val   left join   select   current   用户   rom   

#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

标签:blog   color   上架   val   left join   select   current   用户   rom   

原文地址:http://www.cnblogs.com/Mr-Cxy/p/6166026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!