结构不同的多表关联SQL透视并转为固定格式报表
见附件
SQL代码如下:
SELECT "计划" as 状态, 分公司,计划$.促销品,数量 as 计划数量,数量*价格$.价格 as 计划金额,0 as 变更数量,0 as 变更金额,0 as 实发数量,0 as 实发金额
FROM [价格$],[计划$] WHERE [计划$].促销品=[价格$].促销品
union all
SELECT "变更" as 状态, 分公司,变更$.促销品,0 as 计划数量,0 as 计划金额,数量 as 变更数量,数量*价格$.价格 as 变更金额,0 as 实发数量,0 as 实发金额
FROM [价格$],[变更$] WHERE [变更$].促销品=[价格$].促销品
union all
SELECT "实发" as 状态, 分公司,实发$.促销品,0 as 计划数量,0 as 计划金额,0 as 变更数量,0 as 变更金额,数量 as 实发数量,数量*价格$.价格 as 实发金额
FROM [价格$],[实发$] WHERE [实发$].促销品=[价格$].促销品
[ 本帖最后由 lgcmeli 于 2010-3-3 17:17 编辑 ] |