How does group by works in sequelize?

前端 未结 7 408
不知归路
不知归路 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:54

    I think you looking for something like this:

     Table.findAll({
       attributes: ['column1', 
         sequelize.fn('count', sequelize.col('column2'))], 
       group: ["Table.column1"]
     }).success(function (result) { });
    

    Update: Newer versions of Sequelize uses .then instead of .success.

     Table.findAll({
       attributes: ['column1', 
         sequelize.fn('count', sequelize.col('column2'))], 
       group: ["Table.column1"]
     }).then(function (result) { });
    

提交回复
热议问题