I have a view pulling together data from a number of tables. Let's consider it to be like this:
TransPK Amount Currency_ID
-------------------------------
1 2000 0
1 -2000 0
2 3600 1
2 -7200 2
. . .
I want to calculate sum(Amount), per distinct TransPK, but only where all the Currency_IDs for a given TransPK are the same. i.e. in the data above there would only be one result returned, since for TransPK=2 there are two values for Currency_ID.
I have no idea what to search on for this! I've tried "SQL SUM restricted", but the hits weren't useful. I'm not the first person to want to do something like this. Is anyone able to point me in the right direction?