I ue the followig query in order to calculate the amount for each month as well as the trailing 12 months and to calculate the sums separately. but too slow , how to optimiz