J
Jean
i have couple hundred thousands records in Access 2007; here is a sample:
Hi John I wrote the following query based on yours but it s not working, it
returns records that have called less than 7 times in some instances and the
15 days criteria is not 100% working.
Can you tell me if there is anything wrong with the following query:
SELECT [MS Incidents May-June 08].[Contract #], [MS Incidents May-June
08].[Product Level 2]
FROM [MS Incidents May-June 08] INNER JOIN [MS Incidents May-June 08] AS [MS
Incidents May-June 08_1]
ON [MS Incidents May-June 08].[Contract #] = [MS Incidents May-June
08_1].[Contract #] AND [MS Incidents May-June 08].[Product Level 2] =[MS
Incidents May-June 08_1].[Product Level 2] AND [MS Incidents May-June
08].[Transaction Date]>=[MS Incidents May-June 08_1].[Transaction Date]
And [MS Incidents May-June 08].[Transaction Date]<=[MS Incidents May-June
08_1].[Transaction Date]+15
GROUP BY [MS Incidents May-June 08].[Contract #], [MS Incidents May-June
08].[Product Level 2]
HAVING Count(*)>=7
I need to keep the Contract# and Product Level 2 of records that have:
1. The same Contract# and
2. The same Product Level 2 (call reason) and
3. the # of such records are higher or equal to 7 where the "transaction
date" is between a 15 day range.
The Transaction date has the following format: 6/15/2008 0:57
I am not sure why the query is not working!
Thanks!!
John Spencer said:This query should give you the first record(s) where there have been 6 or more
calls in the following 15 day period.
SELECT A.Account, A.TimeOfCall
FROM Table as A INNER JOIN Table as B
ON A.Account = B.Account and
A.TimeOfCall >= B.TimeOfCall and
A.TimeOfCall <= B.TImeOfCall + 15
GROUP BY A.Account, A.TimeOfCall
Having Count(*) >= 7
You might want to strip off the time component of the TimeOfCall fields if you
are going to count days - although this will slow the query down.
With the above results you could get all the records for the period
SELECT C.*
FROM Table as C
INNER JOIN TheQuery as Q
On C.Account = Q.Account
AND C.TimeOfCall >= Q.TimeOfCall
AND C.TimeOfCall <= Q.TimeOfCall + 15
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County