多表复杂查询请教
有四张表
SalesWasteBook (销售流水表)
------------------
SalesOrderCode
Customercode
ArrivedDateTime(时间)
......
Goods(商品信息)
GoodsName
GoodsCode
Price
.....
Customer(客户信息)
Customername
UpCustomerCode (上级客户编码)
Customercode(本身编码)
........
问题出在这里,比如很多超市有很多分场,现在要统计的是把所有的分场统计在一起,
SalesOrderDetail(销售明细)
---------------
SalesOrderCode
GoodsPrice
Quantity
.............
现在我要查询一段时间内的销售记录,这样查的话,能把所有的查出来,但是不能把分场的归到总的里面,怎么把分场的归到总的里面?
"SELECT B.GoodsCode,B.GoodsName, C.GoodsPrice,Sum(Quantity) As Amount from SalesWasteBook AS A, Goods As
B,SalesOrderDetail C ,Customer As D Where A.SalesOrderCode=C.SalesOrderCode And B.GoodsCode=C.GoodsCode and
C.GoodsCode='"&GoodsCode&"' and A.CustomerCode='"&CustomerCode&"' and ArrivedDateTime>=#"&StartTime&"# and
ArrivedDateTime <#"&EndTIme&"# Group by B.GoodsCode,B.GoodsName, C.GoodsPrice Order By GoodsName Asc"'
现在该怎么改进这个查询?数据库是ACCESS的