SELECT tp.method payment_method,COUNT(t.id) transaction_count,SUM(t.final_total) total_amount,AVG(DATEDIFF(tp.paid_on,t.transaction_date)) avg_payment_days FROM transactions t JOIN transaction_payments tp ON t.id=tp.transaction_id WHERE t.type="sell" GROUP BY tp.method ORDER BY avg_payment_days DESC;