gpt4 book ai didi

mongodb - 复制 PostgreSQL 的窗口函数,如 lag、lead、over

转载 作者:可可西里 更新时间:2023-11-01 09:53:12 29 4
gpt4 key购买 nike

如何将 PostgreSQL 查询更改为 mongodb bson 调用?我在 http://archives.postgresql.org/pgsql-general/2011-10/msg00157.php 中列出了相同的用例我想通过使用滞后或超前之类的东西来计算两个日志条目之间的增量时间。 mongodb 中是否有与 Postgres 的滞后/前导语法类似的内容?

select 
index,
starttime,
endtime,
starttime - lag(endtime) over(order by starttime asc) as delta
from test

http://www.postgresql.org/docs/8.4/static/functions-window.html

我在看 http://www.mongovue.com/2010/11/03/yet-another-mongodb-map-reduce-tutorial/似乎 map/reduce/finalize 应该这样做。 Map id、开始和结束时间,reduce 什么也不做,然后在其自身上进行内部连接(双重 for) 完成。我几乎可以,有点,有点,看到它......

最佳答案

这是您在应用程序中必须要做的事情。目前,mongoDB 不支持这样的东西。

关于mongodb - 复制 PostgreSQL 的窗口函数,如 lag、lead、over,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9185962/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com