我有以下查询(我们称之为Query1)(由here友好创建Erik von Asmuth):
SELECT PARTNERID
,NAME
,FIRST_NAME
,UID
,DATA_R
FROM MY_TABLE
WHERE MY_TABLE.[DATA_R] = (
SELECT MAX(t.[DATA_R])
FROM MY_TABLE AS t
WHERE t.PARTNERID = MY_TABLE.PARTNERID
)
ORDER BY PARTNERID;
MY_TABLE
有20000
个记录,并且是一个查询(即使名称可能暗示相反),使用以下格式:
SELECT [MYTABLE_O].PARTNERID, [MYTABLE_O].NAME, [MYTABLE_O].FIRST_NAME, [MYTABLE_O].[Codice fiscale] AS CF, [MYTABLE_O].Date AS DATA_R
FROM [MYTABLE_O] LEFT JOIN [TO_EXCLUDE] ON [MYTABLE_O].[PARTNERID] = [TO_EXCLUDE].[PARTNERID]
WHERE ((([TO_EXCLUDE].PARTNERID) Is Null));
(我想排除表TO_EXCLUDE
中已经考虑过的一些元素。)
当我运行查询(Query1)时,MS Access会冻结。如何避免它/使其更有效和稳定?
我尝试在MYTABLE_O
和PARTNERID
DATA_R
进行索引
答案 0 :(得分:0)
您可能必须编写子查询的结果:
SELECT PARTNERID, MAX([DATA_R]) AS MAXDATAR
FROM YourQuery
GROUP BY PARTNERID
到临时表,然后在查询中替换
FROM MY_TABLE AS t
与
FROM TempTable AS t