KDB 中按组求和

发布于 2025-01-11 05:49:06 字数 351 浏览 2 评论 0原文

我有一个包含 3 列的 PnL 表。日期、地区、产品。

我正在尝试按地区和产品对所有损益行进行分组。我尝试过的一种方法是按区域和产品求和,如下所示

select PnL : sum(PnL) by Region, Product from table where date inside (d1;d2)

我遇到的问题是意外结果。对于给定的日期范围(d1;d2),我得到了我期望的结果。然而,对于日期范围 (d1;d2+1),我到处都得到 0。

我检查了 d2+1 上的数据可用性,当天数据已经可用。

请注意,服务器是无状态的,并且不可能在变量中使用中间结果。

在 KDB 中实现分组总和的最佳方法是什么?

I have a PnL table with 3 columns. date, region, product.

I'm trying to group all PnL rows by region and product. One way that i've tried is to sum by region and product as following

select PnL : sum(PnL) by region, product from table where date within (d1;d2)

The issue I have is unexpected results. For a given date range (d1;d2) I'm getting the results I'm expecting. However for date range (d1;d2+1) I'm getting 0 everywhere.

I checked the data availability on the d2+1 and data is already available on that day.

Please note that the server is stateless and it is not possible to use intermediate results in variables.

What is the best way to achieve a grouping sum in KDB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文