I'm running into a bear of a problem... My table contains lots of survey data, and looks simular to:
My query is set up to Group by Agent_ID, take the last Agent_name, the last Group_Name, count the Timestamp and average the Avg_Score.. The result looks like this
I had assumed that using the last Group_Name would use the order they appear in the table to judge what is last, but it appears it chooses the last one in alphabetical order. I need the Group_Name to show what group the person was in for the last Survey they recieved.
I did accomplish this by making a query to take the last Timestamp for each Agent_ID, then another query linking that to tblData based on the Timestamp (which is unique) to get the Group_Name and Agent_Name for each Agent_ID, then bringing that all together in my qrySummary which has the Count and Avg score. (there is actually a little more to this that complicates it, but this is the gist)
So, my problem is that by doing this change, the Query runs much slower then before. I've been trying to figure out how to get this into one query, but for the life of me i can't get it figured out. I'm also hoping there is just a plain easier way that i'm missing.
All help is appreciated!
(edited to get my tables to look better)
Code:
Table: tblData
Agent_ID Agent_Name Group_Name TimeStamp Avg_Score
12345 Kyle Team3 1/1/05 8AM 2
12345 Kyle Team3 1/1/05 9AM 3
12345 Kyle Team2 1/1/05 10AM 2
12345 Kyle Team2 1/1/05 11AM 4
12345 Kyle Team2 1/1/05 12PM 1
12345 Kyle Team2 1/1/05 1PM 2
Code:
Query: qrySummary
Agent_ID Agent_Name Group_Name Count Avg_Score
12345 Kyle Team3 6 2.33
I did accomplish this by making a query to take the last Timestamp for each Agent_ID, then another query linking that to tblData based on the Timestamp (which is unique) to get the Group_Name and Agent_Name for each Agent_ID, then bringing that all together in my qrySummary which has the Count and Avg score. (there is actually a little more to this that complicates it, but this is the gist)
So, my problem is that by doing this change, the Query runs much slower then before. I've been trying to figure out how to get this into one query, but for the life of me i can't get it figured out. I'm also hoping there is just a plain easier way that i'm missing.
All help is appreciated!
(edited to get my tables to look better)
Last edited: