假设我在teradata sql中有下面的表。如何获取“最终”列。
第一个值等于“mount”列,第二个值等于最终价格(10-1),第三个值等于(9-2)。
hour mount price
0 10 1
1 10 2
2 10 3
hour mount price final
0 10 1 10
1 10 2 9
2 10 3 7发布于 2019-05-23 05:40:57
您似乎想要一个累积和--然后是与mount的区别
select hour, mount price,
(mount + price -
sum(price) over (order by hour rows between unbounded preceding and current row)
) as final
from t;您真的希望将总和加到前一行。但是如果你使用:
sum(price) over (order by hour rows between unbounded preceding and 1 preceding)然后,您将需要处理NULL值。相反,我只需从当前行添加price,然后让累积和包括该价格。
https://stackoverflow.com/questions/56265368
复制相似问题