Skip to content
Advertisement

Joining on the same table to get 2 different amount values

I want to get the total amount of a funding source (dim_6) against 2 different account codes (1301 AND 1300).

Below is the query that I designed.

The above query doesn’t return the correct sum of amount and it doesn’t match the value of amount if I try to run a simple SQL query against 1 account code, as below

Both the above queries have same conditions but the amount value doesn’t matches if I JOIN.

What am I missing?

Advertisement

Answer

I want to get the total amount of a funding source (dim_6) against 2 different account codes (1301 AND 1300).

Just use conditional aggregation:

Below is the query that I designed.

Note: I’m providing an answer because I think this is a much better solution than the other answer.

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