经测试一下,以下的语句没问题。
select a1.品名,a2.类别,
iif(分类="入库数量",数量,0) as 入库数量,
iif(分类="公司库存",数量,0) as 公司库存,
iif(分类="出库到柜台1",数量,0) as 出库到柜台1,
iif(分类="出库到柜台2",数量,0) as 出库到柜台2,
iif(分类="出库到柜台3",数量,0) as 出库到柜台3,
iif(分类="出库到其他",数量,0) as 出库到其他,
iif(分类="柜台1销售",数量,0) as 柜台1销售,
iif(分类="柜台2销售",数量,0) as 柜台2销售,
iif(分类="柜台3销售",数量,0) as 柜台3销售,
iif(分类="其他销售清单",数量,0) as 其他销售清单,
iif(分类="出库到柜台1",数量,0) - iif(分类="柜台1销售",数量,0) as 柜台1库存,
iif(分类="出库到柜台2",数量,0) - iif(分类="柜台2销售",数量,0) as 柜台2库存,
iif(分类="出库到柜台3",数量,0) - iif(分类="柜台3销售",数量,0) as 柜台3库存,
iif(分类="出库到其他",数量,0) - iif(分类="其他销售清单",数量,0) as 其他库存,
iif(分类="柜台1销售金额",数量,0) as 柜台1销售金额,
iif(分类="柜台2销售金额",数量,0) as 柜台2销售金额,
iif(分类="柜台3销售金额",数量,0) as 柜台3销售金额,
iif(分类="其他销售金额",数量,0) as 其他销售金额
from
(select 品名,val(数量) as 数量,分类
from (select 品名,入库数量 as 数量,"入库数量" as 分类 from [公司出入库$a2:j] union all
select 品名,出库到柜台1,"出库到柜台1" as 分类 from [公司出入库$a2:j] union all
select 品名,出库到柜台2,"出库到柜台2" as 分类 from [公司出入库$a2:j] union all
select 品名,出库到柜台3,"出库到柜台3" as 分类 from [公司出入库$a2:j] union all
select 品名,出库到其他,"出库到其他" as 分类 from [公司出入库$a2:j] union all
select 品名,公司库存,"公司库存" as 分类 from [公司出入库$a2:j] union all
select 品名,数量,"柜台1销售" as 分类 from [柜台1销售清单$a2:j] union all
select 品名,数量,"柜台2销售" as 分类 from [柜台2销售清单$a2:j] union all
select 品名,数量,"柜台3销售" as 分类 from [柜台3销售清单$a2:j] union all
select 品名,数量,"其他销售清单" as 分类 from [其他销售清单$a2:j] union all
select 品名,[金 额],"柜台1销售金额" as 分类 from [柜台1销售清单$a2:j] union all
select 品名,[金 额],"柜台2销售金额" as 分类 from [柜台2销售清单$a2:j] union all
select 品名,[金 额],"柜台3销售金额" as 分类 from [柜台3销售清单$a2:j] union all
select 品名,[金 额],"其他销售金额" as 分类 from [其他销售清单$a2:j] ) where 数量 is not null) a1 right join
(select distinct 类别,品名 from [公司出入库$a2:j] ) a2 on a1.品名=a2.品名 |