我的表有一个timestamp字段,它是标准的RethinkDB日期字段。我可以使用此时间戳字段按天/周/月对行进行分组吗?在group()文档中找不到任何示例。
分别按月,日或星期几分组:
r.table(...).group(r.row('timestamp').month())
r.table(...).group(r.row('timestamp').day())
r.table(...).group(r.row('timestamp').dayOfWeek())
Run Code Online (Sandbox Code Playgroud)
目前,按周进行分组并不容易,因为ReQL当前缺少从数据中获取周数的功能(请参阅https://github.com/rethinkdb/rethinkdb/issues/2055)。您可能可以通过使用一些自定义JavaScript代码来解决此问题r.js()。请告诉我这对您是否重要,所以我可以调查一下。
如果要按多种事物的组合进行分组,例如日和月:
r.table(...).group([r.row('timestamp').month(), r.row('timestamp').day()])
Run Code Online (Sandbox Code Playgroud)