我的系统是用DELPHI做的,用VFP很容易实现,使用DELPHI用临时表也很简单,但用一条SELECT就要动些脑筋了,不过我已经做出来了,分就给大家分了吧,你们都很热心,
Select * From
(
Select 0 As 序列号,仓库号,产品物料编码,物料编码(子物料),领用数量 From 表
Union All
Select 1 As 序列号,仓库号,产品物料编码,'小计' As 物料编码(子物料),Sum(领用数量) From 表 Group By 仓库号,产品物料编码
Union All
Select 2 As 序列号,仓库号,'合计' As 产品物料编码,'' As 物料编码(子物料) ,Sum(领用数量) From 表 Group By 仓库号,产品物料编码
) Order By 序列号,仓库号,产品物料编码
sele 仓库号 from 源数据表 into tabl tck
sele 产品物料编码 from 源数据表 into tabl tcp
sele 源数据表
copy stru to newtable
use newtable in 0
sele tck
go top
scan
sele tcp
go top
scan
sele 源数据表
sum 领用数量 to sl for allt(源数据表.仓库号)==allt(tck.仓库号) and ;
allt(源数据表.产品物料编码)==allt(tcp.产品物料编码)
sele newtable
appe from 源数据表 for allt(源数据表.仓库号)==allt(tck.仓库号) and ;
allt(源数据表.产品物料编码)==allt(tcp.产品物料编码)
appe blan
repl 仓库号 with tck.仓库号,产品物料编码 with tcp.产品物料编码,;
物料编码 with '小计',领用数量 with sl
ends
sele 源数据表
sum 领用数量 to sl for allt(源数据表.仓库号)==allt(tck.仓库号)
sele newtable
appe blan
repl 仓库号 with tck.仓库号,产品物料编码 with '合计',领用数量 with sl
sele tck
ends
sele 源数据表
sum 领用数量 to sl
sele newtable
appe blan
repl 仓库号 with '总计',领用数量 with sl
clos tables all
dele file tck.dbf
dele file tcp.dbf
use newtable in 0
sele newtable
brow