SELECT HOUR(t1.transaction_date) hour,COUNT(DISTINCT t1.id) sales,COUNT(DISTINCT t2.id) returns,COUNT(DISTINCT t2.id)*100.0/COUNT(DISTINCT t1.id) return_rate FROM transactions t1 LEFT JOIN transactions t2 ON t1.id=t2.return_parent_id WHERE t1.type="sell" GROUP BY HOUR(t1.transaction_date) ORDER BY return_rate DESC;