I'm looking for help in how to structure a MS Access SQL query on multiple tables and summarize the results grouped by Project and the sum of the dollar amounts for different types of financial transactions.
The Project table contains meta data about a Project. The Actuals, Budget, and Forecast tables are records of actual and/or planned financial transactions against the Project.
The tables and fields (simplified significantly for this post) are as follows:
Project
--------------
project_id
project_name
project_manager
Budget
--------------
entry_date
project_id
amount
Actuals
--------------
entry_date
project_id
amount
Forecast
--------------
entry_date
project_id
amount
SQL attempt:
SELECT
p.[project_id],
SUM(b.[amount]) AS budget_amount,
SUM(a.[amount]) AS actual_amount,
SUM(f.[amount]) AS forecast_amount
FROM
Project AS p,
Budget AS b,
Actuals AS a,
Forecast AS f
WHERE
p.[project_id] = b.[project_id]
AND b.[project_id] = a.[project_id]
AND a.[project_id] = f.[project_id]
GROUP BY
p.[project_id];
Desired Result:
project_id budget_amount actual_amount forecast_amount
2021-001 $2,000.00 $2,900.00 $2,400.00
2021-002 $3,000.00 $3,500.00 $5,000.00
Actual Result:
project_id budget_amount actual_amount forecast_amount
2021-001 $12,000.00 $17,400.00 $9,600.00
2021-002 $18,000.00 $21,000.00 $20,000.00
Sample Data:
Project
project_id project_name project_manager
2021-001 First Project of 2021 Jack Black
2021-002 Second Project of 2021 James Dean
Actuals
entry_date project_id amount
1/9/2021 2021-001 $1,300.00
1/23/2021 2021-001 $1,600.00
1/9/2021 2021-002 $1,500.00
1/23/2021 2021-002 $2,000.00
Budget
entry_date project_id amount
1/9/2021 2021-001 $1,000.00
1/23/2021 2021-001 $1,000.00
1/9/2021 2021-002 $1,500.00
1/23/2021 2021-002 $1,500.00
Forecast
entry_date project_id amount
1/9/2021 2021-001 $900.00
1/23/2021 2021-001 $1,000.00
2/6/2021 2021-001 $500.00
1/9/2021 2021-002 $1,500.00
1/23/2021 2021-002 $3,000.00
2/6/2021 2021-002 $500.00