zkuste to,
SELECT transaction_date, transaction_type, SUM(transaction_amount)
FROM TableName
-- WHERE customer_id = $customer_id
GROUP BY transaction_date,
CASE WHEN transaction_type = 'refund' THEN 1 ELSE RAND() END
ORDER BY transaction_date DESC