SELECT HOUR(t.transaction_date) hour,COUNT(t.id) transactions,SUM(tsl.quantity) units_sold 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 hour;