在我的数据库(如XXX)中,表名称是“user”
用户表有四列
*-----*------*---------*--------*
| ID | NAME | STATUS | DEBT |
*-----*------*---------*--------*
我想使用舍入函数更新用户表中的 DEBT
原始查询如
"UPDATE users SET DEBT = ROUND(getDebt, 2) WHERE ID = ?"
如何在sequelize中使用round函数?
最佳答案
在sequelize中使用mysql函数的示例(使用sequelize.fn)
models.post.findAll({
include: [
{
model: models.review,
// select attributes
attributes: [
[models.sequelize.fn('avg', models.sequelize.col('stars')), 'rating'],
[models.sequelize.fn('count', '*'), 'count']
],
}
]
})
.then(data=>{
console.log(data);
})
.catch(err=>{
console.log(err);
})
更多信息http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#static-method-fn
关于node.js - 如何在sequelize中使用数字函数(如Round),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48204161/