SELECT CASE WHEN TIMESTAMPDIFF(MINUTE,t.created_at,t.updated_at)<15 THEN "Short" WHEN TIMESTAMPDIFF(MINUTE,t.created_at,t.updated_at)<30 THEN "Medium" ELSE "Long" END period_length,COUNT(t.id) transactions,AVG(t.final_total) avg_value,SUM(t.final_total) total_revenue FROM transactions t WHERE t.type="sell" GROUP BY 1 ORDER BY avg_value DESC;