I have dynamically updated tables. Today I have 30 rows but for the example lets use 3.
Table 1:
color = blue, revenue_yesterday = 40.00
Table 2:
product_id = 1, color = blue, price = 20.00
product_id = 2, color = blue, price = 20.00
product_id = 3, color = red, price = 15.00
I'm going to run a daily/weekly crontab to check for yesterday's or last week's revenue.
I need a script that will get the sum of prices from table 2 by group and update the revenue_yesterday in table 1 where开发者_Go百科 color matches from table 2. Please and thank you.
Update Table1
Set revenue_last_month =
(
Select sum(price)
from Table2
where Table2.color = Table1.color
)
精彩评论