Unanswered: Calculating Total Sum after Giving Discounts

Dear all,
I have a table as follows.
I want to get the sum of points for each login after giving some discount of say 500 points for each.But the discount will be given based on the rank of individual Login.

AA 1 50
AA 3 150
AA 5 25
BB 1 50
BB 2 150
BB 3 550
BB 4 325
BB 5 275
CC 3 250
CC 4 500
CC 5 350

Suppose BB has a total of 1350 points i have to give him a discount of 500 points,it will be given based on the rank he has obtained

BB 1 50 - fully discounted
BB 2 150 - fully discounted
BB 3 550 - partially discounted(300 points disconnted & 250 points kept for accounting)
BB 4 325 - kept for accounting
BB 5 275 - kept for accounting

BB 850

So,in total BB has 850 points to be kept for accounting.And i want this points(850) to be split based on rank .Such as

Login TotalPoints(Accounting) Rank < 3 Rank >= 4
BB 850 250 600

I need to get the individual points and their split up grouped by rank for all the logins as

Login TOTAL POINTS Rank < 3 Rank >=4
AA 0 0 0
BB 850 250 600
CC 600 0 600