Represents a SQL function expression Used in attributes to create aggregate queries
// Count all recordsUser.findAll({ attributes: [[fn('COUNT', col('id')), 'count']]})// Count distinct valuesUser.findAll({ attributes: [[fn('COUNT', fn('DISTINCT', col('role'))), 'uniqueRoles']]})// Sum with group byUser.findAll({ attributes: ['role', [fn('SUM', col('score')), 'totalScore']], group: ['role']}) Copy
// Count all recordsUser.findAll({ attributes: [[fn('COUNT', col('id')), 'count']]})// Count distinct valuesUser.findAll({ attributes: [[fn('COUNT', fn('DISTINCT', col('role'))), 'uniqueRoles']]})// Sum with group byUser.findAll({ attributes: ['role', [fn('SUM', col('score')), 'totalScore']], group: ['role']})
Represents a SQL function expression Used in attributes to create aggregate queries
Example