<i id='XLfrg'><tr id='XLfrg'><dt id='XLfrg'><q id='XLfrg'><span id='XLfrg'><b id='XLfrg'><form id='XLfrg'><ins id='XLfrg'></ins><ul id='XLfrg'></ul><sub id='XLfrg'></sub></form><legend id='XLfrg'></legend><bdo id='XLfrg'><pre id='XLfrg'><center id='XLfrg'></center></pre></bdo></b><th id='XLfrg'></th></span></q></dt></tr></i><div id='XLfrg'><tfoot id='XLfrg'></tfoot><dl id='XLfrg'><fieldset id='XLfrg'></fieldset></dl></div>

    <tfoot id='XLfrg'></tfoot>

      <bdo id='XLfrg'></bdo><ul id='XLfrg'></ul>

  1. <small id='XLfrg'></small><noframes id='XLfrg'>

    1. <legend id='XLfrg'><style id='XLfrg'><dir id='XLfrg'><q id='XLfrg'></q></dir></style></legend>

    2. Sequelize 按日期分组,不考虑小时/分钟/秒

      Sequelize grouping by date, disregarding hours/minutes/seconds(Sequelize 按日期分组,不考虑小时/分钟/秒)
        <bdo id='Bmxe3'></bdo><ul id='Bmxe3'></ul>
      • <legend id='Bmxe3'><style id='Bmxe3'><dir id='Bmxe3'><q id='Bmxe3'></q></dir></style></legend>

                <tbody id='Bmxe3'></tbody>
            1. <small id='Bmxe3'></small><noframes id='Bmxe3'>

                <tfoot id='Bmxe3'></tfoot>
                <i id='Bmxe3'><tr id='Bmxe3'><dt id='Bmxe3'><q id='Bmxe3'><span id='Bmxe3'><b id='Bmxe3'><form id='Bmxe3'><ins id='Bmxe3'></ins><ul id='Bmxe3'></ul><sub id='Bmxe3'></sub></form><legend id='Bmxe3'></legend><bdo id='Bmxe3'><pre id='Bmxe3'><center id='Bmxe3'></center></pre></bdo></b><th id='Bmxe3'></th></span></q></dt></tr></i><div id='Bmxe3'><tfoot id='Bmxe3'></tfoot><dl id='Bmxe3'><fieldset id='Bmxe3'></fieldset></dl></div>

              • 本文介绍了Sequelize 按日期分组,不考虑小时/分钟/秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                嘿,所以我试图从数据库中查询,使用 Sequelize(用于 postgreSQL 的 Node.js ORM),我试图按日期范围分组,并计算该表中有多少项目.

                Hey so im trying to query from a database, using Sequelize (Node.js ORM for postgreSQL), im trying to group by date range, and keep a count of how many items where in that table.

                现在我的代码是

                 Task.findAll({
                    attributes: ['createdAt'],
                    group: 'createdAt'
                  })
                

                但是正如您所见,分组只考虑了确切的日期(包括秒数),因此分组实际上是没有意义的,因为无论如何都不会有具有完全相同秒数的重叠项目.所以我希望它只是基于日、年和月的分组.

                But as you can see the grouping only takes into account the exact date (including seconds) so the grouping is actually pointless since no matter what there will be no overlapping items with the exact same second count. So i want it to just be group based on day, year and month.

                我假设它必须是类似 sequelize.fn(...)

                Im assuming that it will have to be something like sequelize.fn(...)

                推荐答案

                如你所说,用 sequelize.fn(...) 完成,没有别的办法.试试:

                As you said, it's done with sequelize.fn(...) and there is no other way. Try:

                Task.findAll({
                  group: [sequelize.fn('date_trunc', 'day', sequelize.col('createdAt'))]
                })
                

                我认为这可能会完成这项工作.如果没有,我们会看看怎么做;)

                I think that might do the job. If not, we'll see how to do it ;)

                请注意,PostgreSQL 允许您截断到特定的时间间隔.欲了解更多信息,请访问:http://www.postgresql.org/docs/9.1/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

                Notice that PostgreSQL allows you to truncate to specific intervals. For more information visit: http://www.postgresql.org/docs/9.1/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

                另外,要了解组(和顺序)的工作原理,请参阅 Sequelize 的文档:https://github.com/sequelize/sequelize/blob/172272c8be9a847b2d64f0158826738703befddf/docs/docs/models-usage.md#manipulating-the-dataset-with-limit-offset-order-and-group

                Also, to understand how group (and order) works see the documentation of Sequelize: https://github.com/sequelize/sequelize/blob/172272c8be9a847b2d64f0158826738703befddf/docs/docs/models-usage.md#manipulating-the-dataset-with-limit-offset-order-and-group

                这篇关于Sequelize 按日期分组,不考虑小时/分钟/秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
              • <i id='wV5UN'><tr id='wV5UN'><dt id='wV5UN'><q id='wV5UN'><span id='wV5UN'><b id='wV5UN'><form id='wV5UN'><ins id='wV5UN'></ins><ul id='wV5UN'></ul><sub id='wV5UN'></sub></form><legend id='wV5UN'></legend><bdo id='wV5UN'><pre id='wV5UN'><center id='wV5UN'></center></pre></bdo></b><th id='wV5UN'></th></span></q></dt></tr></i><div id='wV5UN'><tfoot id='wV5UN'></tfoot><dl id='wV5UN'><fieldset id='wV5UN'></fieldset></dl></div>
                • <tfoot id='wV5UN'></tfoot>

                • <legend id='wV5UN'><style id='wV5UN'><dir id='wV5UN'><q id='wV5UN'></q></dir></style></legend>

                  1. <small id='wV5UN'></small><noframes id='wV5UN'>

                          <tbody id='wV5UN'></tbody>

                          <bdo id='wV5UN'></bdo><ul id='wV5UN'></ul>