SELECT HOUR(t.transaction_date) hour,COUNT(t.id) transactions,SUM(tsl.unit_price_before_discount*tsl.quantity) total_cost,AVG(tsl.unit_price_before_discount) avg_unit_cost FROM transactions t JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id WHERE t.type="sell" GROUP BY HOUR(t.transaction_date) ORDER BY total_cost DESC;