【发布时间】:2019-04-02 15:21:04
【问题描述】:
我正在尝试使用 Sequelize 获取一些小计,这就是我的查询的样子。
const getAllCustomerEarnings = async (customerAccountId) => {
return await customerEarnings.findAll({
attributes: [
[Sequelize.fn('SUM', Sequelize.col('amount')), 'amount'],
[Sequelize.fn('date_trunc', 'day', Sequelize.col('createdAt')), 'createdAt'],
],
where: {
[Op.and]: [
{customerAccountId: customerAccountId},
]
},
order: [['createdAt', 'ASC']],
group: 'createdAt'
})
}
但是,我得到的输出并不是每天的小计。我实际上从表中获取了每条记录,时间部分设置为 00:00:000Z
为了获得每天的小计,我应该改变什么?
【问题讨论】:
-
你试过用
[Sequelize.fn('date_trunc', 'day', Sequelize.col('createdAt')), 'createdAt']分组 -
是的,没有效果,很遗憾
标签: javascript node.js date sequelize.js grouping