I have a table that captures monthly data totals for aircraft departures and exceptions.
tblData has the following fields: CalMonth, Tail, Exc, SRD
CalMonth is Date/Time with each entry entered as first day of month: 1/1/05, 2/1/02.... 12/1/05. (I'm using only 2005 records to help simplify.)
Tail is Text and contains aircraft numbers: 101, 102, 103... 132
Exc contains number of Exceptions for the month
SRD contains number of Departures for the month
So, tblData has 384 records (12 months x 32 Tails)
I want the 3 month rates of Exceptions [Exc] per 100 Departures [SRD] for each Tail for each month.
If I qry tblData to filter for only one tail, the result is 12 records...
If I use this query I get the 3 month rates...
SELECT qryA.CalMonth, Sum(qryA_1!Exc)/Sum(qryA_1!SRD)*100 AS 3mRate
FROM qryA, qryA AS qryA_1
WHERE (((qryA_1.CalMonth)>DateAdd("m",-3,[qryA]![CalMonth]) And (qryA_1.CalMonth)<=[qryA]![CalMonth]))
GROUP BY qryA.CalMonth
HAVING (((Count(qryA_1.CalMonth))>2));
...The result is 10 records (3/1/05 - 12/1/05) since the first 3 month rate doesn't occur until 3/1/05. I can now use this query in a line chart to show the 3 month rates over time, establish performance standards, etc.
But what I'm really after is the 3 month rate for each Tail in tblData (not just one tail). If I use the above query but replace qryA with tblData, everything goes screwy. This is regardless of whether I bring the Tail field into the query or not...
SELECT tblData.CalMonth, tblData.Tail, Sum([tblData_1].[Exc])/Sum([tblData_1].[SRD])*100 AS Ex_3mRate
FROM tblData, tblData AS tblData_1
WHERE (((tblData_1.CalMonth)>DateAdd("m",-3,[tblData].[CalMonth]) And (tblData_1.CalMonth)<=[tblData].[CalMonth]))
GROUP BY tblData.CalMonth, tblData.Tail
HAVING (((Count(tblData_1.CalMonth))>2));
I'm hoping to end up with 332 records - 10 months(3/1/05-12/1/05) x 32 Tails, with 3 month rate for each displayed.
Can I do this in one query?? Any help would be much appreciated!!
Thanks,
Mike
tblData has the following fields: CalMonth, Tail, Exc, SRD
CalMonth is Date/Time with each entry entered as first day of month: 1/1/05, 2/1/02.... 12/1/05. (I'm using only 2005 records to help simplify.)
Tail is Text and contains aircraft numbers: 101, 102, 103... 132
Exc contains number of Exceptions for the month
SRD contains number of Departures for the month
So, tblData has 384 records (12 months x 32 Tails)
I want the 3 month rates of Exceptions [Exc] per 100 Departures [SRD] for each Tail for each month.
If I qry tblData to filter for only one tail, the result is 12 records...
If I use this query I get the 3 month rates...
SELECT qryA.CalMonth, Sum(qryA_1!Exc)/Sum(qryA_1!SRD)*100 AS 3mRate
FROM qryA, qryA AS qryA_1
WHERE (((qryA_1.CalMonth)>DateAdd("m",-3,[qryA]![CalMonth]) And (qryA_1.CalMonth)<=[qryA]![CalMonth]))
GROUP BY qryA.CalMonth
HAVING (((Count(qryA_1.CalMonth))>2));
...The result is 10 records (3/1/05 - 12/1/05) since the first 3 month rate doesn't occur until 3/1/05. I can now use this query in a line chart to show the 3 month rates over time, establish performance standards, etc.
But what I'm really after is the 3 month rate for each Tail in tblData (not just one tail). If I use the above query but replace qryA with tblData, everything goes screwy. This is regardless of whether I bring the Tail field into the query or not...
SELECT tblData.CalMonth, tblData.Tail, Sum([tblData_1].[Exc])/Sum([tblData_1].[SRD])*100 AS Ex_3mRate
FROM tblData, tblData AS tblData_1
WHERE (((tblData_1.CalMonth)>DateAdd("m",-3,[tblData].[CalMonth]) And (tblData_1.CalMonth)<=[tblData].[CalMonth]))
GROUP BY tblData.CalMonth, tblData.Tail
HAVING (((Count(tblData_1.CalMonth))>2));
I'm hoping to end up with 332 records - 10 months(3/1/05-12/1/05) x 32 Tails, with 3 month rate for each displayed.
Can I do this in one query?? Any help would be much appreciated!!
Thanks,
Mike