S
ScottMSP via AccessMonster.com
Hello,
With a lot of help from Mike Walsh (Vanderghast), I was able to successfully
calculate the quartiles (25th, Median, and 75th) within Access.
The issue I am having now is that when I run the queries, it takes a really
long time to produce the results. I am wondering if there is a way to speed
up the queries to calculate the information.
I have posted below the SQL for the three queries that run to produce the
results. When I test the first two, they run quickly (within seconds), but
the last one (the final one), it is the one that takes too long to produce
the results.
Thanks in advance.
Query1
SELECT tEmployeeMaster.DataEffectiveDate, tEmployeeMaster.JobCode,
tEmployeeMaster.HourlyRate, (SELECT Count (*) FROM tEmployeeMaster AS M1
WHERE M1.JobCode = tEmployeeMaster.JobCode AND M1.DataEffectiveDate =
tEmployeeMaster.DataEffectiveDate AND M1.HourlyRate < tEmployeeMaster.
HourlyRate)+(SELECT Count (*) FROM tEmployeeMaster AS M1 WHERE M1.JobCode =
tEmployeeMaster.JobCode AND M1.DataEffectiveDate = tEmployeeMaster.
DataEffectiveDate AND M1.HourlyRate = tEmployeeMaster.HourlyRate AND M1.
Position <= tEmployeeMaster.Position) AS Rank
FROM tEmployeeMaster
GROUP BY tEmployeeMaster.DataEffectiveDate, tEmployeeMaster.JobCode,
tEmployeeMaster.HourlyRate, tEmployeeMaster.Position
HAVING (((tEmployeeMaster.DataEffectiveDate) Between #4/14/2010# And
#4/16/2010#))
ORDER BY tEmployeeMaster.JobCode, tEmployeeMaster.HourlyRate;
Query2
SELECT qryQuartiles_Sub_Rank.JobCode, Count(qryQuartiles_Sub_Rank.JobCode) AS
CountOfJobCode, 0.25*([CountOfJobCode]+3) AS InterpolQ1, Int([InterpolQ1]) AS
N0Q1, 1-([InterpolQ1]-[N0Q1]) AS Frac0Q1, [N0Q1]+1 AS N1Q1, 1-[Frac0Q1] AS
Frac1Q1, 0.5*([CountOfJobCode]+1) AS InterpolQ2, Int([InterpolQ2]) AS N0Q2, 1-
([InterpolQ2]-[N0Q2]) AS Frac0Q2, [N0Q2]+1 AS N1Q2, 1-[Frac0Q2] AS Frac1Q2, 0.
25*(([CountOfJobCode]*3)+1) AS InterpolQ3, Int([InterpolQ3]) AS N0Q3, 1-(
[InterpolQ3]-[N0Q3]) AS Frac0Q3, [N0Q3]+1 AS N1Q3, 1-[Frac0Q3] AS Frac1Q3
FROM qryQuartiles_Sub_Rank
GROUP BY qryQuartiles_Sub_Rank.JobCode;
Query3
SELECT QryQuartiles_Sub_Interpolation.JobCode, IIf(
[QryQuartiles_Sub_Interpolation].[CountOfJobCode]=1,[qryQuartiles_Sub_Rank].
[HourlyRate],[qryQuartiles_Sub_Rank].[HourlyRate]*[Frac0Q1]+
[qryQuartiles_Sub_Rank_1].[hourlyRate]*[Frac1Q1]) AS Incumbent_Q1, IIf(
[QryQuartiles_Sub_Interpolation].[CountOfJobCode]=1,[qryQuartiles_Sub_Rank].
[HourlyRate],[qryQuartiles_Sub_Rank_2].[HourlyRate]*[Frac0Q2]+
[qryQuartiles_Sub_Rank_3].[hourlyRate]*[Frac1Q2]) AS Incumbent_Q2, IIf(
[QryQuartiles_Sub_Interpolation].[CountOfJobCode]=1,[qryQuartiles_Sub_Rank].
[HourlyRate],[qryQuartiles_Sub_Rank_5].[HourlyRate]*[Frac0Q3]+
[qryQuartiles_Sub_Rank_4].[hourlyRate]*[Frac1Q3]) AS Incumbent_Q3
FROM (((((QryQuartiles_Sub_Interpolation LEFT JOIN qryQuartiles_Sub_Rank ON
(QryQuartiles_Sub_Interpolation.jobCode = qryQuartiles_Sub_Rank.jobCode) AND
(QryQuartiles_Sub_Interpolation.N0Q1 = qryQuartiles_Sub_Rank.Rank)) LEFT JOIN
qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_1 ON
(QryQuartiles_Sub_Interpolation.jobCode = qryQuartiles_Sub_Rank_1.jobCode)
AND (QryQuartiles_Sub_Interpolation.N1Q1 = qryQuartiles_Sub_Rank_1.Rank))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_2 ON
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_2.JobCode)
AND (QryQuartiles_Sub_Interpolation.N1Q2 = qryQuartiles_Sub_Rank_2.Rank))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_3 ON
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_3.JobCode)
AND (QryQuartiles_Sub_Interpolation.N0Q2 = qryQuartiles_Sub_Rank_3.Rank))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_4 ON
(QryQuartiles_Sub_Interpolation.N1Q3 = qryQuartiles_Sub_Rank_4.Rank) AND
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_4.JobCode))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_5 ON
(QryQuartiles_Sub_Interpolation.N0Q3 = qryQuartiles_Sub_Rank_5.Rank) AND
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_5.JobCode);
With a lot of help from Mike Walsh (Vanderghast), I was able to successfully
calculate the quartiles (25th, Median, and 75th) within Access.
The issue I am having now is that when I run the queries, it takes a really
long time to produce the results. I am wondering if there is a way to speed
up the queries to calculate the information.
I have posted below the SQL for the three queries that run to produce the
results. When I test the first two, they run quickly (within seconds), but
the last one (the final one), it is the one that takes too long to produce
the results.
Thanks in advance.
Query1
SELECT tEmployeeMaster.DataEffectiveDate, tEmployeeMaster.JobCode,
tEmployeeMaster.HourlyRate, (SELECT Count (*) FROM tEmployeeMaster AS M1
WHERE M1.JobCode = tEmployeeMaster.JobCode AND M1.DataEffectiveDate =
tEmployeeMaster.DataEffectiveDate AND M1.HourlyRate < tEmployeeMaster.
HourlyRate)+(SELECT Count (*) FROM tEmployeeMaster AS M1 WHERE M1.JobCode =
tEmployeeMaster.JobCode AND M1.DataEffectiveDate = tEmployeeMaster.
DataEffectiveDate AND M1.HourlyRate = tEmployeeMaster.HourlyRate AND M1.
Position <= tEmployeeMaster.Position) AS Rank
FROM tEmployeeMaster
GROUP BY tEmployeeMaster.DataEffectiveDate, tEmployeeMaster.JobCode,
tEmployeeMaster.HourlyRate, tEmployeeMaster.Position
HAVING (((tEmployeeMaster.DataEffectiveDate) Between #4/14/2010# And
#4/16/2010#))
ORDER BY tEmployeeMaster.JobCode, tEmployeeMaster.HourlyRate;
Query2
SELECT qryQuartiles_Sub_Rank.JobCode, Count(qryQuartiles_Sub_Rank.JobCode) AS
CountOfJobCode, 0.25*([CountOfJobCode]+3) AS InterpolQ1, Int([InterpolQ1]) AS
N0Q1, 1-([InterpolQ1]-[N0Q1]) AS Frac0Q1, [N0Q1]+1 AS N1Q1, 1-[Frac0Q1] AS
Frac1Q1, 0.5*([CountOfJobCode]+1) AS InterpolQ2, Int([InterpolQ2]) AS N0Q2, 1-
([InterpolQ2]-[N0Q2]) AS Frac0Q2, [N0Q2]+1 AS N1Q2, 1-[Frac0Q2] AS Frac1Q2, 0.
25*(([CountOfJobCode]*3)+1) AS InterpolQ3, Int([InterpolQ3]) AS N0Q3, 1-(
[InterpolQ3]-[N0Q3]) AS Frac0Q3, [N0Q3]+1 AS N1Q3, 1-[Frac0Q3] AS Frac1Q3
FROM qryQuartiles_Sub_Rank
GROUP BY qryQuartiles_Sub_Rank.JobCode;
Query3
SELECT QryQuartiles_Sub_Interpolation.JobCode, IIf(
[QryQuartiles_Sub_Interpolation].[CountOfJobCode]=1,[qryQuartiles_Sub_Rank].
[HourlyRate],[qryQuartiles_Sub_Rank].[HourlyRate]*[Frac0Q1]+
[qryQuartiles_Sub_Rank_1].[hourlyRate]*[Frac1Q1]) AS Incumbent_Q1, IIf(
[QryQuartiles_Sub_Interpolation].[CountOfJobCode]=1,[qryQuartiles_Sub_Rank].
[HourlyRate],[qryQuartiles_Sub_Rank_2].[HourlyRate]*[Frac0Q2]+
[qryQuartiles_Sub_Rank_3].[hourlyRate]*[Frac1Q2]) AS Incumbent_Q2, IIf(
[QryQuartiles_Sub_Interpolation].[CountOfJobCode]=1,[qryQuartiles_Sub_Rank].
[HourlyRate],[qryQuartiles_Sub_Rank_5].[HourlyRate]*[Frac0Q3]+
[qryQuartiles_Sub_Rank_4].[hourlyRate]*[Frac1Q3]) AS Incumbent_Q3
FROM (((((QryQuartiles_Sub_Interpolation LEFT JOIN qryQuartiles_Sub_Rank ON
(QryQuartiles_Sub_Interpolation.jobCode = qryQuartiles_Sub_Rank.jobCode) AND
(QryQuartiles_Sub_Interpolation.N0Q1 = qryQuartiles_Sub_Rank.Rank)) LEFT JOIN
qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_1 ON
(QryQuartiles_Sub_Interpolation.jobCode = qryQuartiles_Sub_Rank_1.jobCode)
AND (QryQuartiles_Sub_Interpolation.N1Q1 = qryQuartiles_Sub_Rank_1.Rank))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_2 ON
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_2.JobCode)
AND (QryQuartiles_Sub_Interpolation.N1Q2 = qryQuartiles_Sub_Rank_2.Rank))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_3 ON
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_3.JobCode)
AND (QryQuartiles_Sub_Interpolation.N0Q2 = qryQuartiles_Sub_Rank_3.Rank))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_4 ON
(QryQuartiles_Sub_Interpolation.N1Q3 = qryQuartiles_Sub_Rank_4.Rank) AND
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_4.JobCode))
LEFT JOIN qryQuartiles_Sub_Rank AS qryQuartiles_Sub_Rank_5 ON
(QryQuartiles_Sub_Interpolation.N0Q3 = qryQuartiles_Sub_Rank_5.Rank) AND
(QryQuartiles_Sub_Interpolation.JobCode = qryQuartiles_Sub_Rank_5.JobCode);