我看到很多例子,例如:
Model.findAll({
attributes: [[sequelize.fn('COUNT', sequelize.col('hats')), 'no_hats']]
});
但是说除了“COUNT”之外你还需要使用另一个函数,例如
sequelize.fn('LOWERCASE'...
或 sequelize.fn('UNIQUE'...
。有没有办法一次使用多个 sequelize.fn
?更新
我正在寻找一种语法,可以让我在一个
findAll()
中使用两个函数......可能是这样的:Model.findAll({
attributes: [[sequelize.fn(['LOWERCASE','UNIQUE'], sequelize.col('hats'))]
});
最佳答案
我想你可以这样做
Model.findAll({
attributes: [
[sequelize.fn('COUNT', sequelize.col('hats')), 'no_hats'],
[sequelize.fn('LOWERCASE', sequelize.col('name')), 'name'],
[Sequelize.literal('COUNT(DISTINCT(hats))'), 'no_hats']
]
});
关于postgresql - 使用多个 Sequelize.fn?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55997810/