不是很明白,只看出原来的两段查询: sql = "select 加油站,油品编码,油品名称,计量单位 from [库存表$] where 加油站 like '" & JYZName & "'" Sheets("库存日报表").Select [A2].CopyFromRecordset cn.Execute(sql) sql = "select 库存数量,数量2,数量3 as 数量 from (" & _ "(select 编码 from [库存日报表$]) AS A" & _ " left join" & _ " (select 油品编码,库存数量 from [库存表$] where 加油站 like '" & Range("日报表加油站").Value & "') AS B" & _ " ON A.编码=B.油品编码)" & _ " left join" & _ " (select 油品编码,sum(入库数量) as 数量2,sum(销售数量) as 数量3 from [变动表$] where 加油站 like '" & Range("日报表加油站").Value & "' and 日期 > #" & Date1 & "#" & _ " group by 油品编码) AS C" & _ " ON A.编码=C.油品编码" Set temp = cn.Execute(sql) [F2].CopyFromRecordset temp 可以合成一段查询: sql = "select 加油站,A.油品编码,油品名称,计量单位,库存数量-数量2+数量3 as 数量 from " & _ "(select 加油站,油品编码,油品名称,计量单位,库存数量 from [库存表$] where 加油站 like '" & JYZName & "') AS A" & _ " left join" & _ " (select 油品编码,sum(入库数量) as 数量2,sum(销售数量) as 数量3 from [变动表$] where 加油站 like '" & JYZName & "' and 日期 > #" & Date1 & "#" & " group by 油品编码) AS B" & _ " ON A.油品编码=B.油品编码" Sheets("库存日报表").Select [A2].CopyFromRecordset cn.Execute(sql) |