Short version....you can't.
You are going to have to pull that data into a DB and query the data from there.
Otherwise every time you want to find out something you are going to have to parse the entire blockchain.
https://blockchair.com/ has a very good API that is fairly cheap to use if you do not have that many queries that you will do every day.
-Dave