【发布时间】:2014-11-14 21:57:40
【问题描述】:
此 SQL 返回表 Dims 的记录数,而不是返回表 BIDdetails 的记录数。我该如何解决?
BIDReportSearch.CommandText = ("SELECT BIDdetails.Origin, BIDdetails.Destination,
Round(Sum(Dims.ChargeableWeight)) as CWeight, count(BIDdetails.Origin) as NoOfShpt
FROM BIDdetails LEFT JOIN DIMS ON BidDetails.BID=Dims.BID
where BIDdetails.OrgCountry<>'AE' and BIDdetails.DestCountry='AE' and
BIDdetails.ClosingDate>=#" & dtpBIDfrom.Value & "# and BIDdetails.ClosingDate<=#" &
dtpBIDto.Value & "# GROUP BY BIDdetails.Origin, BIDdetails.Destination
ORDER BY Round(Sum(Dims.ChargeableWeight)) DESC")
【问题讨论】:
-
因为,据推测,
Dims在BIDetails中的每一行都有多行,尽管您没有提供足够的细节让我们确定。如果是这种情况,您需要在子查询中进行预聚合。旁注:连接是引入 SQL 注入的好方法,您应该使用参数化查询。
标签: sql ms-access vba left-join ms-access-2010