Шмуэль Б 24:9 Мидраш: Bamidbar Rabbah, Midrash Tanchuma Buber, Midrash Tanchuma & Shir HaShirim Rabbah

וַיִּתֵּ֥ן יוֹאָ֛ב אֶת־מִסְפַּ֥ר מִפְקַד־הָעָ֖ם אֶל־הַמֶּ֑לֶךְ וַתְּהִ֣י יִשְׂרָאֵ֡ל שְׁמֹנֶה֩ מֵא֨וֹת אֶ֤לֶף אִֽישׁ־חַ֙יִל֙ שֹׁ֣לֵֽף חֶ֔רֶב וְאִ֣ישׁ יְהוּדָ֔ה חֲמֵשׁ־מֵא֥וֹת אֶ֖לֶף אִֽישׁ׃

И отдал Иоав сумму нумерации народа царю; и было в Израиле восемьсот тысяч доблестных людей, которые обнажили меч; и было жителей Иудеи пятьсот тысяч человек.

Bamidbar Rabbah

“These are those who were counted of the children of Israel by their patrilineal house; all those counted of the camps according to their hosts were six hundred and three thousand, and five hundred and fifty” (Numbers 2:32).
“These are those who were counted of the children of Israel by their patrilineal house…” In ten places Israel was counted: One, upon their descent to Egypt: “With seventy people, your ancestors descended to Egypt…” (Deuteronomy 10:22). One upon their ascent: “The children of Israel traveled from Rameses to Sukot, some six hundred thousand men on foot” (Exodus 12:37). One after the deed of the calf:24The sin of the Golden Calf. “When you take a census of the children of Israel…” (Exodus 30:12). Two in the book of Numbers; once with the banners, and once with the division of the land. Two in the days of Saul: “He counted them in Tela’im” (I Samuel 15:4), “he counted them in Bazek” (I Samuel 11:8); when they were wealthy, with these lambs,25The word tela’im is also the Hebrew word for lambs. According to the midrash they were not counted in a place called Tela'im, rather they were counted by means of lambs. and when they were poor, with these pebbles.26That is the translation of bazek. One in the days of David: “Yoav gave the sum of the number [mispar] of the census [mifkad] of the people [to the king]” (II Samuel 24:9). If mispar, why mifkad; if mifkad, why mispar?27Mispar and mifkad have similar meanings. Rather, he prepared two notes, a large sum and a small sum. The small one he showed to David; the large one he did not show him.28David and the people were punished for conducting the census. Yoav though that by keeping the larger sum from David, fewer people would be harmed. That is why it wrote et mispar mifkad. One in the days of Ezra: “The entire congregation together was forty[-two] thousand [three hundred and sixty]” (Ezra 2:64). And one in the future: “The flock will pass again under the hands of one who counts” (Jeremiah 33:13).

Midrash Tanchuma Buber

• Once on their descent to Egypt. It is written (in Deut. 10:22): WITH SEVENTY SOULS [DID YOUR ANCESTORS GO DOWN TO EGYPT].
• Once on their coming up, as stated (in Exod. 12:37): THEN THE CHILDREN OF ISRAEL TRAVELED FROM RAMESES TO SUCCOTH, [ABOUT SIX THOUSAND].
• Once <here> in Parashah Ki Tissa.
• Twice in Waydabber (i.e., the book of Numbers):
• Once in <the chapter on> standards (Numb. 2) and
Once in <the chapter on> the division of the land (Numb. 26).
• Twice in the days of Saul: (I Sam. 15:4:) AND HE NUMBERED THEM IN TELAIM. (I Sam. 11:8:) AND HE NUMBERED THEM IN BEZEK.
• Once in the days of David, as stated (in II Sam. 24:9): AND JOAB GAVE THE SUM OF THE NUMBERING OF THE PEOPLE <UNTO THE KING>.
• Once in the coming up from the captivity, as stated (in Ezra 2:64): THE WHOLE CONGREGATION TOGETHER WAS 4 [2360].
• And once in the age to come, [of which it is stated] (in Jer. 33:13): THE SHEEP SHALL PASS AGAIN UNDER THE HANDS OF THE COUNTER.

Midrash Tanchuma

A census of Israel was taken on ten different occasions. The first occurred when they descended to Egypt, as is said: Thy fathers went down into Egypt with three score and ten persons (Deut. 10:29). Again, when they came out of Egypt, as it is said: And the children of Israel journeyed from Rameses to Succoth, about six hundred thousand men (Exod. 12:37). Once in the Book of Numbers (it was taken) with reference to the standards (Num. 2:21); once with regard to the spies (Num. 13);15There is no biblical evidence that a census was taken at the time of the spies.. in the days of Joshua when the land was divided (Josh. 18:10); twice in the time of Saul, as is said: And he numbered them with lambs in Telaim (I Sam. 14:4) and He numbered them with pebbles in Bezek (ibid. 11:8). What is indicated by the word Telaim? When they were prosperous, he counted them by means of their lambs (telayim), but when they were poor in deeds, he counted them with stones. What is bezek? It is a stone. He took a stone for each one of them and then totaled the stones. A census was taken in the days of David, as is said: Joab gave up the sum, the number of the people to the king (II Sam. 24:9); and again at the time of Ezra: The whole congregation together was forty and two thousand, three hundred and three score (Ezra. 2:14). In the time-to-come (a census will be taken), as is said: The flock shall again pass into the hands of Him that counteth them (Jer. 33:13), and in this instance: When thou takest the sum.