The Lord has dealt with me according to my righteousness;
according to the cleanness of my hands he has rewarded me. Psalm 18:20
If our righteousness depended on what we did, we’d be in a very sorry state. It’s one of the largest excuses people will tell you how they think they’ll get to heaven. It goes something like this: “all my good will be weighed against my bad, and I think my good will outweigh the bad.” When questioned further they could not tell you how much good that is – nor can they tell you how much bad that it is. In other words, there are no standards.
With Christ though, none of us meet the standard on our own. “there is none righteous, no not one.”
So, while it seems like David is weighing the bad and the good, he would have known Isaiah 64:6 All of us have become like one who is unclean, and all our righteous acts are like filthy rags.”
David realizes his righteousness is not of his own doing, but that of Christ’s. It’s certainly not from anything David or we did.