S
stevensjn
Hi everyone,
I've been tasked with creating a report (manually, not a report in
Access per se) that details EMS response times. Our service maintains
EMS in a regional municipality that contains many "lower tier"
municipalities. The query needs to be grouped by lower tier and month.
I'm trying to create the report's data set in one query (with a
subquery or some such thing).
The main portion of the query returns average response times based on
DateDiff (in seconds) between a start and stop time that uses the
aggregate AVG grouped by month and lower tier.
I need to add a 90th percentile value which I can't seem to do other
than by running about 200 queries, one for each lower tier, for each
month. As you can imagine that would be a major time sink that I would
like to avoid doing, ever.
Below are the queries. As the tables are quite large I wont post them
just yet, as I'm looking for a concept more than anything else.
LowerTierMaster can be thought of as a lookup of IDs and municipality
names (LowerTier is INT, Municipality is TEXT). Hopefully this is
enough info.
SELECT
MAX(MonthName(Datepart("m", CallDispatched.StartTime))) AS
TheMonth,
MAX(Datepart("m", CallDispatched.StartTime)) AS MonthNum,
MAX(LowerTierMaster.Municipality) AS TheLowerTier,
Count(*) AS NumCalls,
AVG(DateDiff('s',[CallDispatched.StartTime],[CallDispatched.EndTime]))
AS AveResponseTotalSeconds,
AVG(DateDiff('s',CallDispatched.ArriveHospital,CallDispatched.LeaveHospital))
AS AveOffLoadSeconds
FROM
CallDispatched,
LowerTierMaster
WHERE
(CallDispatched.PickupLowerTier = LowerTierMaster.LowerTier) AND
(CallDispatched.StartTime > #09/30/2005 23:59:59# AND
CallDispatched.StartTime < #10/01/2006 00:00:00#) AND
DateDiff("s", CallDispatched.StartTime, CallDispatched.EndTime)
GROUP BY
Datepart("m", CallDispatched.StartTime),
CallDispatched.PickupLowerTier
ORDER BY
2, 3, 4;
I have the following code for running a single 90th percentile on one
lower tier, for one month but I have to build a table of the right data
to run the query on for every month and every lower tier. I would like
to use the results from either the above query ... or a query similar
to the above to make a single data set that I could run a query against
to get the 90th percentiles for all month and lower tiers in one shot.
SELECT
DISTINCT TOP 1 TotalOffloadSeconds
FROM
[SELECT
TOP 90 PERCENT TotalOffloadSeconds,
LowerTier
FROM
tblCallsTemp
WHERE
LowerTier=3731 AND
MonthNum=1
ORDER BY
TotalOffloadSeconds DESC]. AS [90th Percentile]
God help me.
Thanks.
I've been tasked with creating a report (manually, not a report in
Access per se) that details EMS response times. Our service maintains
EMS in a regional municipality that contains many "lower tier"
municipalities. The query needs to be grouped by lower tier and month.
I'm trying to create the report's data set in one query (with a
subquery or some such thing).
The main portion of the query returns average response times based on
DateDiff (in seconds) between a start and stop time that uses the
aggregate AVG grouped by month and lower tier.
I need to add a 90th percentile value which I can't seem to do other
than by running about 200 queries, one for each lower tier, for each
month. As you can imagine that would be a major time sink that I would
like to avoid doing, ever.
Below are the queries. As the tables are quite large I wont post them
just yet, as I'm looking for a concept more than anything else.
LowerTierMaster can be thought of as a lookup of IDs and municipality
names (LowerTier is INT, Municipality is TEXT). Hopefully this is
enough info.
SELECT
MAX(MonthName(Datepart("m", CallDispatched.StartTime))) AS
TheMonth,
MAX(Datepart("m", CallDispatched.StartTime)) AS MonthNum,
MAX(LowerTierMaster.Municipality) AS TheLowerTier,
Count(*) AS NumCalls,
AVG(DateDiff('s',[CallDispatched.StartTime],[CallDispatched.EndTime]))
AS AveResponseTotalSeconds,
AVG(DateDiff('s',CallDispatched.ArriveHospital,CallDispatched.LeaveHospital))
AS AveOffLoadSeconds
FROM
CallDispatched,
LowerTierMaster
WHERE
(CallDispatched.PickupLowerTier = LowerTierMaster.LowerTier) AND
(CallDispatched.StartTime > #09/30/2005 23:59:59# AND
CallDispatched.StartTime < #10/01/2006 00:00:00#) AND
DateDiff("s", CallDispatched.StartTime, CallDispatched.EndTime)
GROUP BY
Datepart("m", CallDispatched.StartTime),
CallDispatched.PickupLowerTier
ORDER BY
2, 3, 4;
I have the following code for running a single 90th percentile on one
lower tier, for one month but I have to build a table of the right data
to run the query on for every month and every lower tier. I would like
to use the results from either the above query ... or a query similar
to the above to make a single data set that I could run a query against
to get the 90th percentiles for all month and lower tiers in one shot.
SELECT
DISTINCT TOP 1 TotalOffloadSeconds
FROM
[SELECT
TOP 90 PERCENT TotalOffloadSeconds,
LowerTier
FROM
tblCallsTemp
WHERE
LowerTier=3731 AND
MonthNum=1
ORDER BY
TotalOffloadSeconds DESC]. AS [90th Percentile]
God help me.
Thanks.