我正在将查询从MS SQL Server中保存的表迁移到MS Access2016。我似乎无法弄清楚如何使用SQL查询中非常常见的max_date内部联接并将其导入到Access查询中。
我已经搜索了该站点,并看到了许多有关如何在SQL中进行操作的说明,而我在SQL中的查询也很好。我的Access查询无法正常工作。
INNER JOIN (
SELECT dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID], max(dbo_LTS_TRANSACTION_HISTORY.[TRANSCATION_DATE]) as [max_trxn_date]
FROM dbo_LTS_TRANSACTION_HISTORY
GROUP BY dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID]) as b
ON dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID] = b.[RFIDTAGID] AND (dbo_LTS_TRANSACTION_HISTORY.[TRANSCATION_DATE] = b.[max_trxn_date]))
我希望我的[TRANSCATION_DATE]
仅保留[max_trxn_date]
,因此每个[RFIDTAGID]
只会提取一个最大日期记录。没有将联接命名为“ b”,我不知道如何进行这项工作。 Access似乎没有采用我在SQL中惯用的命名结构。我在语法上遇到编译错误。
下面的完整代码
SELECT dbo_LTS_TRANSACTION_HISTORY.PROD_ORDER, dbo_LTS_TRANSACTION_HISTORY.PART_NUMBER, dbo_LTS_PACKAGE.QUANTITY, dbo_LTS_TRANSACTION_HISTORY.LOCATION, dbo_LTS_TRANSACTION_HISTORY.TRANSCATION_DATE, dbo_LTS_TRANSACTION_HISTORY.CONTAINER_RFIDTAGID, dbo_LTS_TRANSACTION_HISTORY.RFIDTAGID, dbo_LTS_DISCRETE_JOB_SUMMARY.MFG_DELIVERY_DATE, dbo_LTS_DISCRETE_JOB_SUMMARY.EXTENSION_DATE, dbo_LTS_DISCRETE_JOB_SUMMARY.STATUS, dbo_LTS_DISCRETE_JOB_SUMMARY.PBG, dbo_LTS_LOCATION.TYPE
FROM (dbo_LTS_LOCATION
INNER JOIN (dbo_LTS_DISCRETE_JOB_SUMMARY
INNER JOIN dbo_LTS_TRANSACTION_HISTORY
ON (dbo_LTS_DISCRETE_JOB_SUMMARY.[PROD_ORDER] = dbo_LTS_TRANSACTION_HISTORY.[PROD_ORDER])
AND (dbo_LTS_DISCRETE_JOB_SUMMARY.[DISCRETE_JOB_NUMBER] = dbo_LTS_TRANSACTION_HISTORY.[JOB_NUMBER]))
ON dbo_LTS_LOCATION.[DESIGNATION] = dbo_LTS_TRANSACTION_HISTORY.[LOCATION])
INNER JOIN dbo_LTS_PACKAGE ON dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID] = dbo_LTS_PACKAGE.[RFIDTAGID]
INNER JOIN (
SELECT dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID], max(dbo_LTS_TRANSACTION_HISTORY.[TRANSCATION_DATE]) as [max_trxn_date]
FROM dbo_LTS_TRANSACTION_HISTORY
GROUP BY dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID]) as b
ON dbo_LTS_TRANSACTION_HISTORY.[RFIDTAGID] = b.[RFIDTAGID] AND (dbo_LTS_TRANSACTION_HISTORY.[TRANSCATION_DATE] = b.[max_trxn_date]))
WHERE (((dbo_LTS_TRANSACTION_HISTORY.PROD_ORDER)="123456"));