I’m trying to update sales totals in one table using the existing value plus a sum of values from another table. Here’s a simplified version of the query I’m using:
UPDATE sales_summary
INNER JOIN sales ON sales_summary.StoreID = sales.StoreID
SET sales_summary.total = (sales_summary.total + SUM(sales.amount))
WHERE PurchaseDate BETWEEN '2011-01-01' AND '2011-01-31'
GROUP BY sales_summary.StoreID
Can I not use aggregate functions in an UPDATE?
1 Answer