Skip to content
Advertisement

Access SQL: How to retrieve sums of multiple values where user IDs are assigned to multiple positions

I’m working on an Access database for assigning tasks to personnel and tracking task status and workload. A single user ID can be assigned to one of many fields associated with a particular task. In this case, the Task table has fields for “TechReviewerID” “DesignerID” “TechReviewerWorkload” and “DesignerWorkload.”

I want one query to return one row for each person, with two summary columns totaling all of the workload assigned to them. So if I’m ID1, I want column 3 to return the sum of “TechReviewerWorkload” in all tasks where “TechReviewerID = 1” and column 4 to return the sum of “DesignerWorkload” in all tasks where “DesignerID = 1.”

I have successfully written two separate queries that accomplish this:

This query gives the following table:

I can create a near-identical query by replacing all instances of “designer” terms with “tech reviewer” terms.

What I’m looking for is a table like:

My attempts to combine these two via multiple outer joins resulted in wildly inaccurate sums. I know how to solve that for items on different tables, but I’m not sure how to resolve it when I’m using two items from the same table. Is there some kind of conditional sum I can use in my query that Access supports?

EDIT: Sample Raw Data

Advertisement

Answer

Consider:

Query1: TaskUNION
rearranges data to a normalized structure

Query2:

An alternative would involve 2 simple, filtered aggregate queries on Task table then join those 2 queries to MESPersonnel. Here as all-in-one statement:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement