The current state of Plutus makes this impossible to do. Instead, you have to try and use a custom DB-sync server, and then construct the off-chain code in such a way that it passes the looked-up values to the Haskell program.
Note that you will have to use lifting to ensure that the values parsedpassed by the Haskell code, can configure the Plutus app.
The state of Plutus mentioned here is everything available on and before Feb 22 2022.