javascript - 在 Sequelize 中创建此 SQL
问题描述
我尝试在我的 Sequelize 控制器中创建这个 SQL,但我不知道,data_time 看起来只有 < 30 天。
SQL:
SELECT * FROM bankapplication_transactions
WHERE id_sender = 1
OR id_recipient = 1
AND data_time BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
ORDER BY data_time DESC
续集控制器:
Transaction.findAll({
where: db.Sequelize.and(
{
data_time: moment().add(-30, 'days'), // this is ok?
},
db.Sequelize.or(
{ id_sender: 1 },
{ id_recipient: 1 },
),
),
order: ['data_time', 'DESC'],
}).then(transaction_history => {
if (transaction_history) {
console.log('transaction_history', transaction_history);
}
});
解决方案
var today, afterMonth = new Date();
afterMonth.setMonth(today.getMonth() + 1);
...
where: db.Sequelize.and(
{
data_time: $between: [today , afterMonth ]
},
推荐阅读
- c# - 如何实现 AppCenter 推送 API?
- android - 如何在屏幕上移动 FloatingActionMenu?
- kubernetes - 未从服务端点删除 pod ip 的活动探测失败
- excel - 如何根据引用另一张工作表的真/假公式对范围求和
- sas - 在 sas 中需要相同的输出
- r - 当我更改窗口大小时,传单地图恢复到其原始配置
- pulumi - 无法使用 pulumi 创建新项目
- python - 我想创建一个循环来将不同文本文件中的数据写入单个 excel 文件
- powerbi - PowerQuery - 根据给定值和当前日期查找最近的日期
- c - 访问 tvbuff_t 结构中的字段时,结构的大小未知