Verses 8 through 39 speak of the mighty men of David.
The first three mighty men were Josheb-basshebeth, the chief of the captains, Eleazar, and Shammah (vv. 8-12).
The second three mighty men were those who drew water from the well of Bethlehem for David (vv. 13-23). Abishai, the chief of the three and the most honored among the thirty, became their leader, but he did not attain to the first three (vv. 18-19). Benaiah, more honored than the thirty but not attaining to the first three, was set by David over his guard (vv. 20-23).
Verses 24 through 39 give the names of the thirty mighty men. One of the thirty was Uriah, who was killed by David's conspiracy.
In chapter twenty-four and in 1 Chronicles 21 we have an account of the last sin of David.
Again the anger of Jehovah was kindled against Israel (2 Sam. 24:1a).
Satan moved David against Israel to number Israel and Judah (vv. 1b-2; 1 Chron. 21:1). Satan's moving David to do this was permitted by God.
Joab disagreed with numbering the people and said to David, "Now may Jehovah your God add to the people a hundred times as many as they are, while the eyes of my lord the king may see it. But why does my lord the king desire this thing?" (2 Sam. 24:3).