我有一个表:如何在不使用python或php的情况下计算累计值?
- LOCATION_ID(
location
) - 范围为0-90,000 - 时间(
time_period
) - 1-15范围为每个位置 - 温度(
temp
) - 独特的每个地点的价值x time_period。
示例数据:
location time_period temp
91 1 -4
91 2 3
91 3 12
.......................
.......................
91 15 20
我想创建一个名为cum_temp
新的领域,并为每个小区到那当前TIME_PERIOD增加的累计值。我现在的想法是做复制表并运行:
update site_a
set cum_temp = (select sum(temp)
from site_a_copy
where site_a_copy.location = site_a.location
and site_a_copy.time_period <= site_a.time_period);
这是做到这一点的最有效的方式,也可以提出更好的东西?
只是好奇,但到底是什么温度的总和是什么意思?是只计算平均值吗?我想不出有什么好的理由,但我确信我只是心胸狭隘。 – MJB 2010-07-20 02:00:44
这是特定站点在特定时间内的总体温度。因此,如果我总结时间1到10的所有温度值,则在时间10时,该特定位置点经历了等于该总和的累积温度。我在雪融化和植物生长的情况下使用它。 我没有用它来计算平均值。 – Maiasaura 2010-07-21 02:07:03