老师好,这条sql语句会将bf,jcyj,jryj,lr这四列的和分别放在一个对象中返回
select sum(bf) ,sum(jcyj),sum(jryj),sum(lr) from ledger;
然后我尝试在sequelize中实现这条语句,结果试了好久都没弄出来…麻烦问下老师如何实现啊?
下边这些是我尝试过的代码,只能返回一个字段的和:
const list = await Ledger.findAll({
where: whereOpt,
order: [["id", "desc"]],
// attributes: ["sum", [Sequelize.fn("SUM", Sequelize.col("bf")), "sum"]],
attributes: [[Sequelize.literal("SUM(bf),SUM(lr)"), "result"]],
raw: true,
offset: (pageNumber - 1) * pageSize,
limit: pageSize - 0,
});