在sequelize ORM中计算开始日期和结束日期之间每天的记录数(在nodejs中执行此查询)

发布于 2025-01-13 02:06:20 字数 234 浏览 0 评论 0原文

我将 start_time 和 end_time 作为查询参数传递到 API 中,并希望获得每天从 start_time 到 end_time 的记录计数。 它为我提供了指定开始时间和结束时间之间的记录总数,但我想单独计算每一天的记录数。 示例 start_time:2017-10-07,end_time 为 2017-10-10 所以,我想计算日期的记录数:2017-10-07、2017-10-08、2017-10-09 和 2017-10-10。

I am passing start_time and end_time as a query parameter in an API and want to have count of the records on each day from start_time and end_time.
It is giving me total count of records between the specified start and end_time but I want count for each day individually.
Example start_time: 2017-10-07 and end_time is 2017-10-10
So, I want count for the number of records on the date: 2017-10-07, 2017-10-08, 2017-10-09 and 2017-10-10.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2025-01-20 02:06:21

您希望在 sql 中使用 GROUP BY 子句来按天对计数进行分组。以下是有关如何使用 Sequelize 执行此操作的文档。
https://sequelize.org/master/manual/model-querying- basics.html#grouping

如果您的日期不只是一天,而是有小时和分钟,您可能需要在组中进行一些日期截断通过。以下是一些相关信息:
按日期进行 Sequelize 分组,忽略小时/分钟/秒

You want a GROUP BY clause in your sql to group your count by days. Here's documentation on how to do that with Sequelize.
https://sequelize.org/master/manual/model-querying-basics.html#grouping

And if your date isn't just a single day, but has hours and minutes, you might need to do some date truncation in your group by. Here's some info on that:
Sequelize grouping by date, disregarding hours/minutes/seconds

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文