gpt4 book ai didi

sequelize.js - Sequelize : applying a where clause to a subquery

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

我正在尝试向子查询添加 where 子句,但出现以下错误。我试图做的事情是不可能的吗?

Error: Support for literal replacements in the `where` object has been removed.

models.Message.findAll({
attributes: ['createdAt', 'content',
[
sequelize.literal(`
RANK() OVER (
PARTITION BY DATE_FORMAT('createdAt', '%Y-%m-%d')
ORDER BY createdAt DESC
)`),
'ranked',
]],
where: [sequelize.literal('ranked') <= 3]
})
作为引用,这是我试图在 sequelize 中复制的工作 MySql 查询。
SELECT * FROM (
SELECT
createdAt,
content,
RANK() OVER (
PARTITION BY DATE_FORMAT(`createdAt`, '%Y-%m-%d')
ORDER BY createdAt DESC
) AS ranked
FROM
communication_hub.Messages
ORDER BY createdAt DESC
) AS messages
WHERE ranked <= 3;

最佳答案

使用此代码:

where: sequelize.where(sequelize.col('ranked'), '<=',  3)

关于sequelize.js - Sequelize : applying a where clause to a subquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64775013/

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