SELECT tp.method payment_method,COUNT(t.id) transactions,SUM(t.final_total) total_sales FROM transactions t JOIN transaction_payments tp ON t.id=tp.transaction_id WHERE t.type="sell" AND t.status="final" GROUP BY tp.method ORDER BY total_sales DESC;