The sages of Alexandria asked: What should a person do to become wealthy? Rabbi Yehoshua said to them: He should increase his time involved in merchandise and conduct his business faithfully. The sages of Alexandria said to Rabbi Yehoshua: Many people have done so, and it did not help them become rich. Rabbi Yehoshua replied: Rather, they should pray for mercy to receive wisdom from the One to Whom wealth belongs, as it is stated: “Mine is the silver, and Mine the gold, says the Lord of hosts” (Haggai 2:8).
The Gemara cites another statement by the same Sages. Rav Avira interpreted a verse homiletically. Sometimes he would say it in the name of Rav Ami, and sometimes he would say it in the name of Rav Asi: What is the meaning of that which is written: “Thus says the Lord: Though they be in full strength [shelemim], and likewise many, even so shall they be cut down, and he shall pass away; and though I have afflicted you, I will afflict you no more” (Nahum 1:12). This means: If a person sees that his sustenance is limited he should use it for charity, and all the more so when it is plentiful. In other words, if his livelihood has finished [nishlam] he should perform charity, and he should certainly act in this manner if his means are plentiful.
And Rabbi Elazar says: Any person in whom there is knowledge ultimately becomes wealthy, as it is stated: “And by knowledge are the chambers filled with all precious and pleasant riches” (Proverbs 24:4).
"Every person who possesses understanding will ultimately become rich etc." This seems challenging, for it is said, "[N]or yet bread to the wise,"(Ecclesiastes 9:11) etc. This can be resolved according to what is said in the second chapter of Niddah: 'What should a person do to become wealthy?' It is said to him, 'Increase in commerce, etc.' He said, 'Many have done so and it was not beneficial. Rather, he should seek mercy from the One who possesses the wealth.' This is the meaning of 'whoever has understanding will ultimately become wealthy.' At first, he increases in commerce, and ultimately, when he sees through his intellect and understanding that this was not beneficial, he decides to seek mercy from the One who possesses the wealth. This is the opposite of 'whoever does not possess understanding will ultimately become impoverished,' etc. Because he increases in commerce and it does not benefit him, and since he lacks understanding, he does not seek mercy, and ultimately becomes poor. He is exiled even from his place as he needs to sell it due to his hardship."
...
I have further observed under the sun that
The race is not won by the swift,Nor the battle by the valiant;Nor is bread won by the wise,Nor wealth by the intelligent,Nor favor by the learned.
For the time of mischance comes to all.