Thanks for using JustAnswer. This is Leela and I will help you with the question today.
I can help you update the SQL query.
Can you please provide DATABASE TABLE SCHEMA details so that i can work on the query.
If we can do a remote session that would be great so that we can try the query directly on your environment directly.