How does group by works in sequelize?

前端 未结 7 503
不知归路
不知归路 2020-12-16 09:18

I am looking for group by queries through Sequelize and cannot seem to find any documentation.

    SELEC         


        
7条回答
  •  借酒劲吻你
    2020-12-16 09:50

    Group by with count sequelize ORM

    'field' - you can rename this string, it's your field(column) in database

    'count' - reserved string need for get count in sequelize

    'cnt' - you can rename this string, it's your output count

    Sequelize version 3.25.0

    User.findAll({
          attributes: ['field', [sequelize.fn('count', sequelize.col('field')), 'cnt']],
          group: ['field'],
    })
    

提交回复
热议问题