sql - LIKE 表达式的左侧必须计算为 varchar?
问题描述
我正在编写一个带有基于字段内字符串的过滤器的查询。但是,我正在运行它显示错误的查询:
LIKE 表达式的左侧必须计算为 varchar
我希望每个购买了基于custom_field
.
这是自定义字段内的示例数据:
{ "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%'
推荐阅读
- laravel - Laravel 的背包:多列顺序不起作用
- javascript - 像鼠标效果一样增加五彩纸屑的大小
- database - 我的移动应用程序需要数据库还是应该将所有内容保存到文件中?
- python - 创建 TCP 聊天室并在线程中出错
- twitter-bootstrap - 谷歌浏览器突然开始自动打开引导时间和日期选择器
- twilio - Twilio SIP 域不允许入站呼叫
- c# - 如何在 Linux/Ubuntu 上的 VSCode for Unity 中获得 C# 脚本的代码完成?
- python - 无法通过 python MSAL 使用身份验证代码流
- c++ - 将整数划分为 k 个不同的整数 (C++)
- python - GeneratorsNeeded error in sympy 提取多项式系数