我有一张 table a_daily 像
这样的列1.date
2.FromDate
3.Target
4.Cumulative_Target
我将每天添加行 因此每天都会引用 fromdate 和 date Cumulative_Target 列进行更新,如表中所示
这就是我需要做的:
date Fromdate Target Cumulative_Target
2012-04-16 2012-04-16 500 500 '(cycle1-started)
2012-04-17 2012-04-16 500 1000
2012-04-18 2012-04-16 800 1800
'
'
'
2012-05-15 2012-04-16 200 xxxxxx '(cycle1-completed)
2012-05-16 2012-05-16 150 150 '(cycle2-started)
2012-05-17 2012-05-16 100 250
2012-05-18 2012-05-16 700 950
'
'
'
'
2012-06-15 2012-06-15 200 xxxxx '(Cycle2-completed)
因此表中的起始日期每个周期都会有所不同
我用于更新的查询是:
UPDATE a_daily
SET a_daily.Cumulative_Generation = sum(a_daily.Target)
between a_daily.Date and a_daily.From_Date
我不知道如何化妆计算列请帮助我!!
最佳答案
尝试这个查询 -
SET @count = 0;
UPDATE a_daily
SET Cumulative_Target = @count:= target + @count
ORDER BY date
...如果需要请指定您的订单条款
关于mysql - 在两个日期范围之间更新表内的列时,组函数的使用无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13488730/