SQL = "SELECT SPD.商品编码,SPD.商品名称,SPD.商品规格,SPD.单位," SQL = SQL & "IIF(ISNULL(AA.进货数量合计),0,AA.进货数量合计)-IIF(ISNULL(BB.销售数量合计),0,BB.销售数量合计) as 数量," SQL = SQL & "IIF(ISNULL(AA.进货金额合计),0,AA.进货金额合计)-IIF(ISNULL(BB.销售金额合计),0,BB.销售金额合计) as 金额 " SQL = SQL & "from( SPD left JOIN (select SPD.商品编码,B.进货数量合计,B.进货金额合计" SQL = SQL & " from SPD left JOIN (select JHD.商品编码,sum(进货数量) as 进货数量合计,sum(进货金额) as 进货金额合计" SQL = SQL & " from JHD where MID(进货清单号,3,8)<" & TextBox1.Value & " group by JHD.商品编码 ) B on SPD.商品编码=B.商品编码) AA on SPD.商品编码=AA.商品编码 )" SQL = SQL & " left JOIN (select SPD.商品编码,A.销售数量合计,A.销售金额合计 from SPD left JOIN (SELECT XSD.商品编码,SUM(销售数量) AS 销售数量合计,sum(销售成本) as 销售金额合计" SQL = SQL & " from XSD where MID(销售清单号,3,8)< " & TextBox1.Value & " group by XSD.商品编码 ) A on SPD.商品编码=A.商品编码) BB on SPD.商品编码=BB.商品编码 " 上述代码是从http://club.excelhome.net/dispbbs.asp?boardid=2&replyid=404679&id=169114&page=1&skin=0&Star=3 中复制过来的!看不懂,请版主指教 谢! |