gpt4 book ai didi

node.js - 将 SQL 查询与之间转换为 Sequelize

转载 作者:行者123 更新时间:2023-12-03 22:24:44 27 4
gpt4 key购买 nike

我已经尝试了几天在 node.js 中使用带有 Sequelize 文字的 between 运算符运行 SQL 查询,但我完全无法。该查询在 SQL 中运行良好,但我可以在 sequelize 中实现它。有人可以帮我吗?这是 SQL 代码:

SELECT * FROM vs_app_demoes.order_planned WHERE
433869 BETWEEN
cast(substr(cast(barcode AS CHAR),1,6) AS SIGNED) AND
cast(substr(cast(barcode AS CHAR),1,6) AS SIGNED) + barcodeunits
AND paneno = 2

最佳答案

您可以用两个 BETWEEN<= 用 AND 连接来替换 >=:

const prders = await OrderPlanned({
where: {
[Op.and]: [
Sequelize.where(Sequilize.literal('cast(substr(cast(barcode AS CHAR),1,6) AS SIGNED)'), '<=', 433869),
Sequelize.where(Sequilize.literal('(cast(substr(cast(barcode AS CHAR),1,6) AS SIGNED) + barcodeunits)'), '>=', 433869),
paneno: 2
]
}
})

关于node.js - 将 SQL 查询与之间转换为 Sequelize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65967340/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com