|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
原帖由 zm0115 于 2009-12-25 13:06 发表
这select K.日期,K.部门,K.供货商,K.产品型号,K.销售数量,K.销售金额,K.销售数量*K.进货平均价 as 进货成本 FROM (Select A.日期 as 日期,A.部门 as 部门,A.供货商 as 供货商,A.产品型号 as 产品型号,sum(A.销售数量) as 销售数量,sum(A.销售金额) as 销售金额,(select sum(进货金额)/sum(进货数量) from [进货$] where 标志=A.供货商&A.产品型号) AS 进货平均价 from [销售原表$] as A group by A.日期,A.部门,A.供货商,A.产品型号) as K
上面这段语句的设计思路值得琢磨!~~
我的写法:
select A1.*,A2.进货金额汇总/A2.进货数量汇总 as 进货均价,A1.销售数量汇总*(A2.进货金额汇总/A2.进货数量汇总) as 进货成本 from (select 月份,产品型号,部门,供货商,sum(销售数量) as 销售数量汇总,sum(销售金额) as 销售金额汇总 from (select month(日期) as 月份,销售数量,销售金额,产品型号,部门,供货商 from [销售数据$]) group by 月份,产品型号,部门,供货商)A1,
(select 月份,产品型号,供货商,sum(进货数量) as 进货数量汇总,sum(进货金额) as 进货金额汇总 from(select month(日期) as 月份,供货商,产品型号,进货数量,进货金额 from [进货$]) group by 月份,产品型号,供货商)A2 where A1.月份=A2.月份 and A1.供货商=A2.供货商 and A1.产品型号=A2.产品型号 |
|