SELECT p.name,COUNT(DISTINCT v.id) variation_count,AVG(tsl.unit_price_before_discount) avg_cost,STDDEV(tsl.unit_price_before_discount) cost_variability FROM products p LEFT JOIN variations v ON p.id=v.product_id JOIN transaction_sell_lines tsl ON p.id=tsl.product_id JOIN transactions t ON tsl.transaction_id=t.id WHERE t.type="sell" GROUP BY p.id,p.name ORDER BY variation_count DESC;