Help with query for multiple totals
I need a hand with a query of an access database.
Basically, I just need the SQL code behind this query.
I've got a table that has quite a bit of fields in it, but the ones that are of concern are:
ScorecardID (Primary Key)
EmployeeID (occurs multiple times, each employee has a bunch of 'scorecards' in this table)
Score (a % value - their grade)
ScorecardType (value from 1-13 which identifies what type of scorecard this is)
There is also another table which holds information about all the employees. This table will have EVERY employee in it.. the tblScorecard table will just show employees that have scorecards.
EmployeeID (matches up to employee ID in the tblScorecard table)
StaffName (name of the employee)
Basically here is what I need:
I need to write a query which lists off each EmployeeID (preferably everyone that exists in tblBluebook, although I would be OK with just having the people that have scorecards), their Average Score (i.e. Avg(Score) ) of all their Scorecards, a Count of all the scorecards where ScorecardType = 1, a Count of all the scorecards where ScorecardType = 2, etc.... up to a Count of all the scorecards where ScorecardType = 13.
I'm trying to wrap my head around how to do this with just one query. The only way I've thought of so far is to have one query that lists every employee, then open up another query that checks the avg score and total of scorecardtype = 1, then another query for 2, etc... up to 13. However, as you can guess, this will mean that there will be THOUSANDS of queries to the database, as opposed to possibly just 1.
Anyone know how I can do this in just 1 query? A union perhaps? I'm not sure what the union would look like in this case.... any help would be appreciated here.