Skip to content
Advertisement

Query over multiple tables including SUM

I am looking for the correct syntax

I can set up different queries but I am looking for one query

Tables:

Desired result: (minus the calculation in brackets, that’s for clarity)

If I do something like this I get wrong totals under the SUM columns

EDIT Sorry, I forgot to include a Pnum in the first table. I will add it and will play around with the answers. Table T1 is not very important. It only needs some info from there depending on the Pnum in T2

Advertisement

Answer

Try something like this (apologies for the vague references, but it seems that your original example is already somewhat simplified from reality):

Basically, you are creating your aggregate rows and your “work” rows separately, then combining them into one table and ordering the result to “group” them together.

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