There are problems we face that come upon us unexpectedly, like a solder who must face a "troop" out in the field. Other conflicts we see coming, like a solder commanded to attack a city wall.
"For by You..." We have a companion; one who willingly and joyfully goes with us through our task. Remember God is near. "by You..." It is like David is talking to someone right next to him. We should always remember to pray. As two solders must constantly stay in communication in battle so we also must constantly talk it through with our God.
Remember it is not by our ideas or inner strength that we overcome the challenges of our life, but, "By my God..." It is by my God. we must turn to God, and remember what we know about Him. With prayer I need to invite Him along to the battle. I could say more about the nature of Christian victory but the point now is "By God." It is not just ''by God's help." No, that would suggest He is only a partner like a 50/50 him and me thing; instead it is 100% by God that I can run against a troop or leap a wall.
We might say I won the game by a strategy, or we finished the job by hard work. We are giving credit to the power that accomplished a thing. David was giving credit to the One who truly deserves it.