Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

GROUP BY apenas linhas com uma determinada condição e data


experimente isso,
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