如何获得 Snowflake 的累积乘积?
我想在雪花中计算跨行的累积产品。
基本上,我每月的费率在整个时间内累积。
(某些数据库为此具有product()
SQL函数)。
I want to calculate the cumulative product across rows in Snowflake.
Basically I have monthly rates that multiplied accumulate across time.
(Some databases have the product()
SQL function for that).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sterling Paramore 建议的技巧:添加日志,然后对其求幂:
A trick suggested by Sterling Paramore: Add logs, and then exponentiate it:
如果内置函数不存在,通常可以使用 用户定义的表函数。
在本例中:
示例表:
调用 UDTF:
注意 empty over() 子句 强制 Snowflake 对数据执行单次顺序运行,而不是将其拆分为并行块
If a built-in function doesn't exist, it's usually possible to roll something custom using a User-Defined Table Function.
In this case:
Example table:
invoking the UDTF:
Note the empty over() clause which forces Snowflake to do a single sequential run over the data instead of splitting it into parallel chunks