I'm struggling with this specific Access 2010 SQL query for quite some time now. Let me first show you what my table looks like:
customerID value
123456789 100
123456789 -100
123456789 300
123456789 -300
123456789 150
123456789 -150
123456789 200
123456789 200
987654321 500
987654321 -500
987654321 200
987654321 -200
987654321 210
987654321 210
You see I have multiple entries for one customerID with several values. These values can be positive and negative. Negative values represent corrections so the corresponding positive value "gets nulled".
What I need to query now is the maximum value of all maximum values per customerID. In the example above, the maximum value of customerID 123456789 is 200, because all other values on this customerID annul each other. The maximum value on customerID 987654321 hence is 210.
Ultimately my query should return the value of 210 as the maximum out of all maximum values per customerID that didn't get corrected/anulled by negative values.
Can you please help me with this?
Edit: Added (duplicate) values 200 and 210 to both customerIDs to make clear that a SUM() wont work here.
Edit #2: Here's some (nearly) real life data: http://pastebin.com/TbNRTw5A