简体   繁体   中英

MS Access - query that sums a sum through multiple joined tables

I have three tables Models , Buildups , and Components with many-to-many join tables in between them. Each model can have multiple buildups and buildups are composed of multiple components. The components table has a field called Retail .

I'm trying to create a query for a report where the user can see a model and know the total buildup retail amount which would be the sum of the Retail field of each component in the buildup and then a sum of each buildup in the model.

I need a way to reference the Sum of the Sum of components without the enter parameter box appearing when the query is run (strange enough, when the parameter box is left blank it calculates correctly but I don't want the box to pop up).

Is the solution a nested query? If so, how would I do that? Or is the solution to use DSum() ? Once again, if so, how would I implement that?

I'm not sure what to reference to make the criteria portion of the DSum() formula work correctly.

Unless I've misunderstood your database structure or what you are looking to obtain, it seems like this would be sufficient:

select 
    mo.JandelModelID,
    sum(co.retail) as Total_Retail
from
    (   
        (
            tblJandelModels mo inner join tblJandelModelBuildups mb on
            mo.JandelModelID = mb.JandelModelID
        ) 
        inner join tblBuildupComponents bc on mb.BuildupID = bc.BuildupID
    )
    inner join tblComponents co on bc.ComponentID = co.ComponentID
group by
    mo.JandelModelID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM