的问题是,这个查询挂起或具有我不知道如何使用的MS Access修复无限记录:SELECT INTO查询使用NOT IN子查询需要较长的时间/挂起
预期的用户输入:
User input Start Date: 1/15/2015
User input End Date: 11/15/2015
User input Upper Data Threshold in kB: 50
源表:
[Master] Table in Access:
Invc Date Mobile Nbr PktDtVol
--------- ---------- --------
1/15/15 647-409-8206 48kB
2/15/15 647-409-8206 33kB
3/15/15 647-409-8206 8000kB
4/15/15 647-409-8206 20kB
5/15/15 647-409-8206 10kB
6/15/15 647-409-8206 0kB
7/15/15 718-500-2311 3kB
8/15/15 718-500-2311 45kB
9/15/15 718-500-2311 25kB
10/15/15 514-300-3311 33kB
11/15/15 514-300-3311 20kB
输出在[Temp_Table]:
Invc Date Mobile Nbr PktDtVol Difference in Days
--------- ---------- -------- -------------------
7/15/15 718-500-2311 3kB 304
8/15/15 718-500-2311 45kB 304
9/15/15 718-500-2311 25kB 304
10/15/15 514-300-3311 33kB 304
11/15/15 514-300-3311 20kB 304
接受SQL方案产生上述输出:
PARAMETERS [Start Date] DateTime, [End Date] DateTime, [Upper Bound Usage in KB] IEEEDouble;
SELECT m.[Invc Date], m.PktDtVol, m.[Mobile Nbr], DateDiff("d",[Start Date],[End Date]) AS [Difference in days]
INTO Temp_Table FROM Master AS m
WHERE (m.[Invc Date]>=[Start Date] And m.[Invc Date])<=[End Date] AND m.[Mobile Nbr] NOT IN
(SELECT q.[Mobile Nbr] FROM Master AS q WHERE (q.PktDtVol>=[Upper Bound Usage in KB]));
从这里,我试图创建一个索引通过另一SQL语句修改表以优化查询,但不工作:
CREATE INDEX Index2 ON Master([Ttl Charges])
该查询正常工作,没有挂在源表中的10条记录与多个记录与预期的输出。但是,如果源表中有多条记录的56,000条记录,则会出现此问题。
@ChristopherD。 - 不,那不是他们想要的。有关详细信息,请参阅他们的[早期问题](http://stackoverflow.com/q/40856980/2144390)。 –
大于或等于上限?这看起来是正确的。我建议小于或等于上限。如果它是上面的,你就小于。 – Fionnuala
@Fionnuala'q.PktDtVol> = [上限KB用法]'正常工作。它成功排除了上限用法以上的记录。 – stitch70