1 Chronicles 21:2-12

2 And David said to Joab and to the rulers of the people, Go, number Israel from Beersheba even to Dan; and bring the number of them to me, that I may know it.
3 And Joab answered, The LORD make his people an hundred times so many more as they be: but, my lord the king, are they not all my lord's servants? why then doth my lord require this thing? why will he be a cause of trespass to Israel?
4 Nevertheless the king's word prevailed against Joab. Wherefore Joab departed, and went throughout all Israel, and came to Jerusalem.
5 And Joab gave the sum of the number of the people unto David. And all they of Israel were a thousand thousand and an hundred thousand men that drew sword: and Judah was four hundred threescore and ten thousand men that drew sword.
6 But Levi and Benjamin counted he not among them: for the king's word was abominable to Joab.
7 And God was displeased* with this thing; therefore he smote Israel.
8 And David said unto God, I have sinned greatly, because I have done this thing: but now, I beseech thee, do away the iniquity of thy servant; for I have done very foolishly.
9 And the LORD spake unto Gad, David's seer, saying,
10 Go and tell David, saying, Thus saith the LORD, I offera thee three things: choose thee one of them, that I may do it unto thee.
11 So Gad came to David, and said unto him, Thus saith the LORD, Chooseb thee
12 Either three years' famine; or three months to be destroyed before thy foes, while that the sword of thine enemies overtaketh thee; or else three days the sword of the LORD, even the pestilence, in the land, and the angel of the LORD destroying throughout all the coasts of Israel. Now therefore advise thyself what word I shall bring again to him that sent me.