SELECT p.name,DATEDIFF(CURRENT_DATE,p.created_at) product_age_days,COUNT(t.id) total_sales FROM products p LEFT JOIN transaction_sell_lines tsl ON p.id=tsl.product_id LEFT JOIN transactions t ON tsl.transaction_id=t.id AND t.type="sell" GROUP BY p.id,p.name,p.created_at ORDER BY total_sales DESC;