I have this query below, and I am doing a lot of subqueries. Is this a good way to do it? If not can anybody please tell me how to write/optimize this query in a better way?