gpt4 book ai didi

sql - 在 Sequelize 查询 wheres 属性中使用别名?

转载 作者:行者123 更新时间:2023-12-03 22:26:23 25 4
gpt4 key购买 nike

这是我的示例代码,我的问题是如何在查询中将 'cityName' 设为别名

const test = await test.findAll({
where: { cityName: { $like: '%' + searchWord + '%' } },
attributes: ['a', 'b']
})

对不起我的英语水平
这是我的附加说明,我想使用参数来替换“cityName”
let NewCityName = 'something'

const test = await test.findAll({
where: { NewCityName: { $like: '%' + searchWord + '%' } },
attributes: ['a', 'b']
})

这段代码不起作用,但它似乎有助于理解这个问题。

最佳答案

是的,这是可能的。试试这个。

const test = await test.findAll({
where: { cityName: { $like: '%' + searchWord + '%' } },
attributes: ['id',['cityName', 'city']]
})

这里 cityName 将别名为 city

关于sql - 在 Sequelize 查询 wheres 属性中使用别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278847/

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