在访问2007中执行以下查询时出错,如何解决?
我的查询是:
SELECT
A.PRODUCT
, A.DISPBANK
, COUNT(*) AS RecCount
, SUM(Amt) AS TotAmt
FROM
CBWCFAPENDINGPAYMENTDATA A
WHERE
A.MATCH ='Y'
AND A.ID LIKE'*(SELECT [CASHIN_ID] FROM CBWCFAMISUPLOAD WHERE VENDOR='BRINKS' AND NZ(MATCH,'')='Y')*'
GROUP BY
A.PRODUCT
, A.DISPBANK
答案 0 :(得分:1)
LIKE字符串中不能有子查询。
您可以使用DLookup和字符串连接。
AND A.ID LIKE '*' &
DLookup("[CASHIN_ID]", "CBWCFAMISUPLOAD", "VENDOR='BRINKS' AND NZ(MATCH,'')='Y'" ) & '*'
答案 1 :(得分:1)
好的,所以你的答案应该如下所示,如果表有一对多的关系,你将计算你需要的东西,并返回表a中找到id的表a中的所有行:
SELECT A.PRODUCT, A.DISPBANK,Count(*) as RecCount,Sum(Amt) as TotAmt FROM CBWCFAPENDINGPAYMENTDATA A WHERE A.MATCH="Y" AND Format(CStr([A.ID])) IN (SELECT [CASHIN_ID] FROM CBWCFAMISUPLOAD WHERE VENDOR="BRINKS" AND NZ(MATCH,"")="Y")) GROUP BY A.PRODUCT, A.DISPBANK