You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WITH solds AS (SELECT p.product_id, u.units, p.price FROM UnitsSold u LEFT JOIN prices p ON u.product_id = p.product_id AND u.purchase_date BETWEEN p.start_date AND p.end_date)
SELECT product_id, ROUND(CONVERT(FLOAT, SUM(units * price)) / SUM(units), 2) AS average_price FROM solds GROUP BY product_id