想找找论坛上的高人,看看有没有更好的办法求出此表结果数据.要求生成速度快!
TbA
NoidateqtyA
A2007/06/0110
A2007/06/025
A2007/06/048
B2007/06/0212
B2007/06/038
B2007/06/2020
B2007/06/2215
….………
TbB
No qtyB
A20
B25
..
要求按日期从小到大排序结取出如下数据
NOidateQtyB用掉QtyAQtyA剩余
A2007/06/0120100
A2007/06/022050
A2007/06/042053
B2007/06/0225120
B2007/06/032580
B2007/06/2025515
请指点一下,谢了.
[解决办法]
select A.NO,idate,QtyB,qtyA as 用掉QtyA,QtyB-qtyA as QtyA剩余 from TbA a left join TbB b on a.NO=b.NO ORDER BY 1,2 into table temp1
go top
lcbl=alltrim(no)
lnsum=qtyb
scan
if alltrim(no) <> lcbl
lnsum=qtyb
lcbl=alltrim(no)
endif
replace QtyA剩余 with abs(lnsum-用掉QtyA)
lnsum=abs(lnsum-用掉QtyA)
endscan