SELECT tp.method payment_method,COUNT(t.id) transactions,AVG(CASE WHEN DATEDIFF(tp.paid_on,t.transaction_date)<=7 THEN t.final_total ELSE NULL END) early_payment_avg,AVG(CASE WHEN DATEDIFF(tp.paid_on,t.transaction_date)>7 THEN t.final_total ELSE NULL END) regular_payment_avg FROM transactions t JOIN transaction_payments tp ON t.id=tp.transaction_id WHERE t.type="sell" GROUP BY tp.method;