How does group by works in sequelize?
issue: https://github.com/sequelize/sequelize/issues/348
User.findAll({ group: ['field']})
i use sequelize@2.0.0-dev9
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) { });
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'],})