SELECT p.name,AVG(DATEDIFF(t2.transaction_date,t1.transaction_date)) avg_days FROM products p JOIN transaction_sell_lines tsl1 ON p.id=tsl1.product_id JOIN transactions t1 ON tsl1.transaction_id=t1.id JOIN transactions t2 ON t1.contact_id=t2.contact_id AND t2.id>t1.id WHERE t1.type="sell" GROUP BY p.id,p.name HAVING avg_days IS NOT NULL ORDER BY avg_days;