如何使用sequelize框架实现对两字段乘积后求和的运算?
如何使用sequelize框架实现对两字段乘积后求和的运算?
SELECT sum(volume) as total_volume, sum(price * volume) as total_price, currency from trades
4 回复
为什么非要用sequelize的orm,sequelize也可以用sql。两者互补不是很好么。
sequelize.query(`SELECT sum(volume) as total_volume, sum(price * volume) as total_price, currency from trades`, {
type: sequelize.QueryTypes.SELECT
})
其实就用到sum
,也不一定非得写 SQL 语句
用 models.sequelize.fn('sum', col1, col2)
这样的函数