gpt4 book ai didi

sql - LIKE 表达式的左侧必须计算为 varchar 吗?

转载 作者:行者123 更新时间:2023-12-04 02:47:42 26 4
gpt4 key购买 nike

我正在根据字段内的字符串编写带有过滤器的查询。但是,我正在运行查询它显示错误:

Left side of LIKE expression must evaluate to a varchar



我希望所有购买宝马的人都基于 custom_field fFilter .

这是自定义字段内的示例数据:
{ "car_model;":"BMWZ4", "car_id":"0980291", "manufacture":"bmw" }

代码:
SELECT
first_name,
Last_name,
country,
custom_field
FROM
sales_table
WHERE
custom_field LIKE '%BMWZ4%'

预期结果
first_name: John   
last_name: Parker
country: Germany
custom_field: {"car_model;":"BMWZ4","car_id":"098222291","brand":"bmw"}

最佳答案

SELECT
first_name,
Last_name,
country,
custom_field
FROM sales_table
WHERE cast( custom_field as varchar(max)) LIKE '%BMWZ4%'

关于sql - LIKE 表达式的左侧必须计算为 varchar 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678744/

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