SELECT HOUR(t.transaction_date) hour,AVG(tsl.unit_price_before_discount) avg_price,MIN(tsl.unit_price_before_discount) min_price,MAX(tsl.unit_price_before_discount) max_price 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 avg_price DESC;