Sorry if I've misunderstood your question. If you are using a custom query on the data from your database. You could easily put that "custom query" into a view if your database technology supports it and connect to that view. That way you will be able to mirror the same results as if you ran the query on your database.
Hope this helps