I have a SQL query which I ran for > 2 hours and had to stop it because it was taking long time. Would someone be able to give me pointers to optimize this query?