refactor step Replace Temp with Query on total_amount