我有一张类似于下表的表格。我试图找出今天所有价格的总和。
| id| price | created |
|---|-------|----------------------|
| 0 | 500 | 2018-04-02 11:40:48 |
| 1 | 2000 | 2018-04-02 11:40:48 |
| 2 | 4000 | 2018-07-02 11:40:48 |
下面的代码是我想出的,但它似乎不起作用。
const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
where: {
created: TODAY,
},
});
console.log(SUM);
即使今天有条目,SUM 的值也为 0。我也尝试了以下方法,但也没有用。
const TODAY = new Date();
const SUM = await OrdersModel.sum('price', {
where: {
created: Sequelize.DATE(TODAY),
},
});
console.log(SUM);
终端查询的SQL语句如下。
执行(默认): SELECT sum(`price`) AS `sum` FROM `orders` AS `orders` WHERE `orders`.`created` = '2019-05-27 18:30:00';