select "期初",规格型号,机器号,数量,0 as 数量3, 0 as 数量2, 金额,0 as 金额3, 0 as 金额2 from [期初$] union all
select "入库",规格型号,机器号, 0 as 数量2, 数量,0 as 数量3, 0 as 金额2, 金额,0 as 金额3 from [入库$] union all
select "出库",规格型号,机器号, 0 as 数量3, 0 as 数量2,数量, 0 as 金额3, 0 as 金额2,金额 from [出库$]
1、数量3是入库,它位于第一行SQL查询语句数量的第2个位置;第二行,第三行中的数量,无论是叫什么名字,只要在第2个位置的就是入库,第三个位置的就是出库。
2、透视表的字段取自SQL查询语句第一行的名称。
楼上的很是仔细啊! 个人建议语句中的数量明确到入库还是出库比较好,看起来容易理解,如下这种样式:
select "期初",规格型号,机器号, 数量 as 期初数量,0 as 入库数量, 0 as 出库数量, 金额 as 期初金额,0 as 入库金额, 0 as 出库金额 from [期初$] union all
select "入库",规格型号,机器号, 0 as 期初数量,数量 as 入库数量, 0 as 出库数量, 0 as 期初金额,金额 as 入库金额, 0 as 出库金额 from [入库$] union all
select "出库",规格型号,机器号, 0 as 期初数量,0 as 入库数量, 数量 as 出库数量, 0 as 期初金额,0 as 入库金额, 金额 as 出库金额 from [出库$]
[ 本帖最后由 penghaifeng 于 2009-8-6 13:03 编辑 ] |