SELECT CASE WHEN TIMESTAMPDIFF(MINUTE,t.created_at,t.updated_at)<15 THEN "<15 min" WHEN TIMESTAMPDIFF(MINUTE,t.created_at,t.updated_at)<30 THEN "15-30 min" ELSE ">30 min" END duration,COUNT(t.id) transactions,COUNT(DISTINCT t.contact_id) customers,AVG(t.final_total) avg_value FROM transactions t WHERE t.type="sell" GROUP BY 1 ORDER BY avg_value DESC;