By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,488 Members | 2,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,488 IT Pros & Developers. It's quick & easy.

A very slow running query

P: n/a
I hope this isn't too confusing.

The following query runs pretty fast by itself, but when I want to use it in
a report (pasted below the query), it takes at least fifteen seconds to run!
Then I want to analyze the query in Excel and I have to do some manual
tweaking. I'd like to run this same query as a summary for the whole class
without having to manually do it in Excel, rather in an Access report, but
that gets even more complicated.

Here's the Access SQL:

SELECT students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname] AS student,
[activities].[activityWeight]/DSum("activityweight","activities","groupID="
& [groups].[groupID]) AS ActivityPercentageWeight,
[groups].[groupWeight]/DSum("groupweight","groups","courseCode= '" &
[courses].[courseCode] & "'") AS GroupPercentageWeight,
[score]*[ActivityPercentageWeight]*[GroupPercentageWeight] AS
activityPoints, courses.courseDescription, activities.activityDescription
FROM students INNER JOIN (((courses INNER JOIN groups ON courses.courseCode
= groups.courseCode) INNER JOIN studentsInCourses ON courses.courseCode =
studentsInCourses.courseCode) INNER JOIN (activities INNER JOIN
studentScores ON activities.activityID = studentScores.activityID) ON
groups.groupID = activities.groupID) ON (students.studentID =
studentsInCourses.studentID) AND (students.studentID =
studentScores.studentID)
GROUP BY students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname], courses.courseDescription,
activities.activityDescription;
I wonder how I could rewrite this to run faster? Or maybe the problem is
how the data is being retrieved in the report? Should I send the code
behind the report?

Here is an example of an actual student grade sheet (formatted for text, not
the actual formatting). It is based on a crosstab query called
qryStudentSummary (above).

Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group Participation Score Weight % Weight
Writing Center 0.0 1.0 50.00%
Discussion 75.0 1.0 50.00%
Group Weight: 10.0 total for group 3.75%
Group Critical Thinking Score Weight % Weight
Critical Thinking 0.0 1.0 100.00%
Group Weight: 5.0 total for group 0.00%
Group Essays Score Weight % Weight
Reflection 73.0 60.0 12.77%
Letter 10 Editor 75.0 35.0 7.45%
Scholarship 70.0 35.0 7.45%
Comparison 62.0 70.0 14.89%
Causal Analysis 75.0 80.0 17.02%
Definition 57.0 90.0 19.15%
Argument 75.0 100.0 21.28%
Group Weight: 30.0 total for group 20.70%
Group Research Score Weight % Weight
5 Power Figures 100.0 5.0 2.50%
Machiavelli Summary 100.0 5.0 2.50%
Proposal 100.0 5.0 2.50%
Annotated Bibliography 100.0 15.0 7.50%
Outline 87.0 10.0 5.00%
1st Draft 52.0 10.0 5.00%
2nd Draft 77.0 100.0 50.00%
3rd draft 0.0 50.0 25.00%
Group Weight: 15.0 total for group 9.07%
Group Exams Score Weight % Weight
Midterm 75.0 5.0 100.00%
Group Weight: 30.0 total for group 22.50%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group In Class Work Score Weight % Weight
Cause/Effect Outline 100.0 1.0 4.55%
In-class Machiavelli 0.0 1.0 4.55%
Wooden 100.0 1.0 4.55%
Comparison introduction 100.0 1.0 4.55%
Cause/Effect Intro 100.0 1.0 4.55%
Rousseau 3 0.0 1.0 4.55%
Argument Proposal 100.0 1.0 4.55%
Definition Metaphor 100.0 1.0 4.55%
Definition Intro 0.0 1.0 4.55%
Rousseau 2 100.0 1.0 4.55%
Boys and Girls 0.0 1.0 4.55%
Rousseau 1 100.0 1.0 4.55%
Smith/Marx 0.0 1.0 4.55%
Smith/Marx essay 100.0 1.0 4.55%
Aristotle 100.0 1.0 4.55%
Gardner 100.0 1.0 4.55%
Self Evaluation 100.0 1.0 4.55%
Keynes/Galbraith/Reich 0.0 1.0 4.55%
Comparison Discussion 100.0 1.0 4.55%
Shipwreck 0.0 1.0 4.55%
Thoreau/King 50.0 1.0 4.55%
Eduction Discussion 100.0 1.0 4.55%
Group Weight: 10.0 total for group 6.59%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007
Course Average: 62.61%
Extra Credit 1.00%
Total 63.61% D
Although a letter grade of D is not considered failing, you must
earn a grade of C or better to pass to the next level. Please seek
help.
The letter grades work like this:
A = 92 or higher
B = 82-91
C = 72-81
D = 62-71
F = 61 or below

Jun 7 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
See, if I include the group weights, group names, activity weights, and
activity names, it creates a bunch of extra rows. So I have to make an
extra step of plugging that data in manually in an Excel database, when I
would much rather create an Access report to do the same thing. It's hard
to format in text:

Each column: Group, Group weight, Activity, Activity Weight all above name.
Then beside each name within each column the score at the intersection.
first column below the first several rows:
Name:

Each column thereafter will be the scores.

If I weren't so close to this I would be confused. I get a little confused
just trying to explain the situation. I really do understand the problem.
I just don't know how to solve it. I'm in the middle of creating web pages
that will show the problem graphically with screen shots and code behind the
forms, etc.
"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:CCM9i.216$ng.19@trnddc07...
>I hope this isn't too confusing.

The following query runs pretty fast by itself, but when I want to use it
in a report (pasted below the query), it takes at least fifteen seconds to
run! Then I want to analyze the query in Excel and I have to do some
manual tweaking. I'd like to run this same query as a summary for the
whole class without having to manually do it in Excel, rather in an Access
report, but that gets even more complicated.

Here's the Access SQL:

SELECT students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname] AS student,
[activities].[activityWeight]/DSum("activityweight","activities","groupID="
& [groups].[groupID]) AS ActivityPercentageWeight,
[groups].[groupWeight]/DSum("groupweight","groups","courseCode= '" &
[courses].[courseCode] & "'") AS GroupPercentageWeight,
[score]*[ActivityPercentageWeight]*[GroupPercentageWeight] AS
activityPoints, courses.courseDescription, activities.activityDescription
FROM students INNER JOIN (((courses INNER JOIN groups ON
courses.courseCode = groups.courseCode) INNER JOIN studentsInCourses ON
courses.courseCode = studentsInCourses.courseCode) INNER JOIN (activities
INNER JOIN studentScores ON activities.activityID =
studentScores.activityID) ON groups.groupID = activities.groupID) ON
(students.studentID = studentsInCourses.studentID) AND (students.studentID
= studentScores.studentID)
GROUP BY students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname], courses.courseDescription,
activities.activityDescription;
I wonder how I could rewrite this to run faster? Or maybe the problem is
how the data is being retrieved in the report? Should I send the code
behind the report?

Here is an example of an actual student grade sheet (formatted for text,
not the actual formatting). It is based on a crosstab query called
qryStudentSummary (above).

Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group Participation Score Weight % Weight
Writing Center 0.0 1.0 50.00%
Discussion 75.0 1.0 50.00%
Group Weight: 10.0 total for group 3.75%
Group Critical Thinking Score Weight % Weight
Critical Thinking 0.0 1.0 100.00%
Group Weight: 5.0 total for group 0.00%
Group Essays Score Weight % Weight
Reflection 73.0 60.0 12.77%
Letter 10 Editor 75.0 35.0 7.45%
Scholarship 70.0 35.0 7.45%
Comparison 62.0 70.0 14.89%
Causal Analysis 75.0 80.0 17.02%
Definition 57.0 90.0 19.15%
Argument 75.0 100.0 21.28%
Group Weight: 30.0 total for group 20.70%
Group Research Score Weight % Weight
5 Power Figures 100.0 5.0 2.50%
Machiavelli Summary 100.0 5.0 2.50%
Proposal 100.0 5.0 2.50%
Annotated Bibliography 100.0 15.0 7.50%
Outline 87.0 10.0 5.00%
1st Draft 52.0 10.0 5.00%
2nd Draft 77.0 100.0 50.00%
3rd draft 0.0 50.0 25.00%
Group Weight: 15.0 total for group 9.07%
Group Exams Score Weight % Weight
Midterm 75.0 5.0 100.00%
Group Weight: 30.0 total for group 22.50%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group In Class Work Score Weight % Weight
Cause/Effect Outline 100.0 1.0 4.55%
In-class Machiavelli 0.0 1.0 4.55%
Wooden 100.0 1.0 4.55%
Comparison introduction 100.0 1.0 4.55%
Cause/Effect Intro 100.0 1.0 4.55%
Rousseau 3 0.0 1.0 4.55%
Argument Proposal 100.0 1.0 4.55%
Definition Metaphor 100.0 1.0 4.55%
Definition Intro 0.0 1.0 4.55%
Rousseau 2 100.0 1.0 4.55%
Boys and Girls 0.0 1.0 4.55%
Rousseau 1 100.0 1.0 4.55%
Smith/Marx 0.0 1.0 4.55%
Smith/Marx essay 100.0 1.0 4.55%
Aristotle 100.0 1.0 4.55%
Gardner 100.0 1.0 4.55%
Self Evaluation 100.0 1.0 4.55%
Keynes/Galbraith/Reich 0.0 1.0 4.55%
Comparison Discussion 100.0 1.0 4.55%
Shipwreck 0.0 1.0 4.55%
Thoreau/King 50.0 1.0 4.55%
Eduction Discussion 100.0 1.0 4.55%
Group Weight: 10.0 total for group 6.59%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007
Course Average: 62.61%
Extra Credit 1.00%
Total 63.61% D
Although a letter grade of D is not considered failing, you must
earn a grade of C or better to pass to the next level. Please seek
help.
The letter grades work like this:
A = 92 or higher
B = 82-91
C = 72-81
D = 62-71
F = 61 or below



Jun 7 '07 #2

P: n/a
Actually a different query does a much better job but it doesn't include the
Activity and Group data. I can't use it for the grades sheet but it does
work for the spreadsheet. I just can't figure out how to get the Activity
and Group data into it without creating a bunch of extra rows:

PARAMETERS [Forms]![frmSelectCourse]![cboSelectCourse] Text ( 255 );
TRANSFORM Sum(studentScores.score) AS SumOfscore
SELECT studentsInCourses.courseCode, courses.courseDescription, [lName] & ",
" & [fName] & " " & [StudentNumber] AS Student
FROM students INNER JOIN (((courses INNER JOIN groups ON courses.courseCode
= groups.courseCode) INNER JOIN studentsInCourses ON courses.courseCode =
studentsInCourses.courseCode) INNER JOIN (activities INNER JOIN
studentScores ON activities.activityID = studentScores.activityID) ON
groups.groupID = activities.groupID) ON (students.studentID =
studentsInCourses.studentID) AND (students.studentID =
studentScores.studentID)
WHERE
(((studentsInCourses.courseCode)=[Forms]![frmSelectCourse]![cboSelectCourse]))
GROUP BY studentsInCourses.courseCode, courses.courseDescription, [lName] &
", " & [fName] & " " & [StudentNumber]
ORDER BY studentsInCourses.courseCode
PIVOT activities.activityDescription;

Group name and Group weight are both in a table called groups. Activity
name and Activity Weight are in a table called activities.

"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:CCM9i.216$ng.19@trnddc07...
>I hope this isn't too confusing.

The following query runs pretty fast by itself, but when I want to use it
in a report (pasted below the query), it takes at least fifteen seconds to
run! Then I want to analyze the query in Excel and I have to do some
manual tweaking. I'd like to run this same query as a summary for the
whole class without having to manually do it in Excel, rather in an Access
report, but that gets even more complicated.

Here's the Access SQL:

SELECT students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname] AS student,
[activities].[activityWeight]/DSum("activityweight","activities","groupID="
& [groups].[groupID]) AS ActivityPercentageWeight,
[groups].[groupWeight]/DSum("groupweight","groups","courseCode= '" &
[courses].[courseCode] & "'") AS GroupPercentageWeight,
[score]*[ActivityPercentageWeight]*[GroupPercentageWeight] AS
activityPoints, courses.courseDescription, activities.activityDescription
FROM students INNER JOIN (((courses INNER JOIN groups ON
courses.courseCode = groups.courseCode) INNER JOIN studentsInCourses ON
courses.courseCode = studentsInCourses.courseCode) INNER JOIN (activities
INNER JOIN studentScores ON activities.activityID =
studentScores.activityID) ON groups.groupID = activities.groupID) ON
(students.studentID = studentsInCourses.studentID) AND (students.studentID
= studentScores.studentID)
GROUP BY students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname], courses.courseDescription,
activities.activityDescription;
I wonder how I could rewrite this to run faster? Or maybe the problem is
how the data is being retrieved in the report? Should I send the code
behind the report?

Here is an example of an actual student grade sheet (formatted for text,
not the actual formatting). It is based on a crosstab query called
qryStudentSummary (above).

Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group Participation Score Weight % Weight
Writing Center 0.0 1.0 50.00%
Discussion 75.0 1.0 50.00%
Group Weight: 10.0 total for group 3.75%
Group Critical Thinking Score Weight % Weight
Critical Thinking 0.0 1.0 100.00%
Group Weight: 5.0 total for group 0.00%
Group Essays Score Weight % Weight
Reflection 73.0 60.0 12.77%
Letter 10 Editor 75.0 35.0 7.45%
Scholarship 70.0 35.0 7.45%
Comparison 62.0 70.0 14.89%
Causal Analysis 75.0 80.0 17.02%
Definition 57.0 90.0 19.15%
Argument 75.0 100.0 21.28%
Group Weight: 30.0 total for group 20.70%
Group Research Score Weight % Weight
5 Power Figures 100.0 5.0 2.50%
Machiavelli Summary 100.0 5.0 2.50%
Proposal 100.0 5.0 2.50%
Annotated Bibliography 100.0 15.0 7.50%
Outline 87.0 10.0 5.00%
1st Draft 52.0 10.0 5.00%
2nd Draft 77.0 100.0 50.00%
3rd draft 0.0 50.0 25.00%
Group Weight: 15.0 total for group 9.07%
Group Exams Score Weight % Weight
Midterm 75.0 5.0 100.00%
Group Weight: 30.0 total for group 22.50%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group In Class Work Score Weight % Weight
Cause/Effect Outline 100.0 1.0 4.55%
In-class Machiavelli 0.0 1.0 4.55%
Wooden 100.0 1.0 4.55%
Comparison introduction 100.0 1.0 4.55%
Cause/Effect Intro 100.0 1.0 4.55%
Rousseau 3 0.0 1.0 4.55%
Argument Proposal 100.0 1.0 4.55%
Definition Metaphor 100.0 1.0 4.55%
Definition Intro 0.0 1.0 4.55%
Rousseau 2 100.0 1.0 4.55%
Boys and Girls 0.0 1.0 4.55%
Rousseau 1 100.0 1.0 4.55%
Smith/Marx 0.0 1.0 4.55%
Smith/Marx essay 100.0 1.0 4.55%
Aristotle 100.0 1.0 4.55%
Gardner 100.0 1.0 4.55%
Self Evaluation 100.0 1.0 4.55%
Keynes/Galbraith/Reich 0.0 1.0 4.55%
Comparison Discussion 100.0 1.0 4.55%
Shipwreck 0.0 1.0 4.55%
Thoreau/King 50.0 1.0 4.55%
Eduction Discussion 100.0 1.0 4.55%
Group Weight: 10.0 total for group 6.59%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007
Course Average: 62.61%
Extra Credit 1.00%
Total 63.61% D
Although a letter grade of D is not considered failing, you must
earn a grade of C or better to pass to the next level. Please seek
help.
The letter grades work like this:
A = 92 or higher
B = 82-91
C = 72-81
D = 62-71
F = 61 or below



Jun 7 '07 #3

P: n/a
Richard Hollenbeck wrote:
I hope this isn't too confusing.

The following query runs pretty fast by itself, but when I want to use it in
a report (pasted below the query), it takes at least fifteen seconds to run!
Then I want to analyze the query in Excel and I have to do some manual
tweaking. I'd like to run this same query as a summary for the whole class
without having to manually do it in Excel, rather in an Access report, but
that gets even more complicated.
Sometimes what I will do is create a couple of sub queries that
gets/rolls up specific data. IOW, I would take your query and break it
up. Then create a new query and add those queries and any other tables
still missing and run it.

>
Here's the Access SQL:

SELECT students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname] AS student,
[activities].[activityWeight]/DSum("activityweight","activities","groupID="
& [groups].[groupID]) AS ActivityPercentageWeight,
[groups].[groupWeight]/DSum("groupweight","groups","courseCode= '" &
[courses].[courseCode] & "'") AS GroupPercentageWeight,
[score]*[ActivityPercentageWeight]*[GroupPercentageWeight] AS
activityPoints, courses.courseDescription, activities.activityDescription
FROM students INNER JOIN (((courses INNER JOIN groups ON courses.courseCode
= groups.courseCode) INNER JOIN studentsInCourses ON courses.courseCode =
studentsInCourses.courseCode) INNER JOIN (activities INNER JOIN
studentScores ON activities.activityID = studentScores.activityID) ON
groups.groupID = activities.groupID) ON (students.studentID =
studentsInCourses.studentID) AND (students.studentID =
studentScores.studentID)
GROUP BY students.studentID, courses.courseCode, groups.groupID,
activities.activityID, groups.groupWeight, groups.groupOrder,
activities.activityWeight, activities.activityOrder, studentScores.score,
students.[lname] & ", " & [fname], courses.courseDescription,
activities.activityDescription;
I wonder how I could rewrite this to run faster? Or maybe the problem is
how the data is being retrieved in the report? Should I send the code
behind the report?

Here is an example of an actual student grade sheet (formatted for text, not
the actual formatting). It is based on a crosstab query called
qryStudentSummary (above).

Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group Participation Score Weight % Weight
Writing Center 0.0 1.0 50.00%
Discussion 75.0 1.0 50.00%
Group Weight: 10.0 total for group 3.75%
Group Critical Thinking Score Weight % Weight
Critical Thinking 0.0 1.0 100.00%
Group Weight: 5.0 total for group 0.00%
Group Essays Score Weight % Weight
Reflection 73.0 60.0 12.77%
Letter 10 Editor 75.0 35.0 7.45%
Scholarship 70.0 35.0 7.45%
Comparison 62.0 70.0 14.89%
Causal Analysis 75.0 80.0 17.02%
Definition 57.0 90.0 19.15%
Argument 75.0 100.0 21.28%
Group Weight: 30.0 total for group 20.70%
Group Research Score Weight % Weight
5 Power Figures 100.0 5.0 2.50%
Machiavelli Summary 100.0 5.0 2.50%
Proposal 100.0 5.0 2.50%
Annotated Bibliography 100.0 15.0 7.50%
Outline 87.0 10.0 5.00%
1st Draft 52.0 10.0 5.00%
2nd Draft 77.0 100.0 50.00%
3rd draft 0.0 50.0 25.00%
Group Weight: 15.0 total for group 9.07%
Group Exams Score Weight % Weight
Midterm 75.0 5.0 100.00%
Group Weight: 30.0 total for group 22.50%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007

Group In Class Work Score Weight % Weight
Cause/Effect Outline 100.0 1.0 4.55%
In-class Machiavelli 0.0 1.0 4.55%
Wooden 100.0 1.0 4.55%
Comparison introduction 100.0 1.0 4.55%
Cause/Effect Intro 100.0 1.0 4.55%
Rousseau 3 0.0 1.0 4.55%
Argument Proposal 100.0 1.0 4.55%
Definition Metaphor 100.0 1.0 4.55%
Definition Intro 0.0 1.0 4.55%
Rousseau 2 100.0 1.0 4.55%
Boys and Girls 0.0 1.0 4.55%
Rousseau 1 100.0 1.0 4.55%
Smith/Marx 0.0 1.0 4.55%
Smith/Marx essay 100.0 1.0 4.55%
Aristotle 100.0 1.0 4.55%
Gardner 100.0 1.0 4.55%
Self Evaluation 100.0 1.0 4.55%
Keynes/Galbraith/Reich 0.0 1.0 4.55%
Comparison Discussion 100.0 1.0 4.55%
Shipwreck 0.0 1.0 4.55%
Thoreau/King 50.0 1.0 4.55%
Eduction Discussion 100.0 1.0 4.55%
Group Weight: 10.0 total for group 6.59%
(next page)
Student Summary for: (NAME DELETED FOR PRIVACY)
45768 Course 2007 Spring English 1A MW 2 pm
Wednesday, June 06, 2007
Course Average: 62.61%
Extra Credit 1.00%
Total 63.61% D
Although a letter grade of D is not considered failing, you must
earn a grade of C or better to pass to the next level. Please seek
help.
The letter grades work like this:
A = 92 or higher
B = 82-91
C = 72-81
D = 62-71
F = 61 or below


Jun 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.