我正在寻找一种方法来根据另一列的数据在一列中选择某些内容。我有 2 个表:
input_table - has a column called "year_of_birth"
result_table - has a column called "notes"
您看,“注释”列可能包含年份,例如“1980”。我需要能够选择 notes 字段包含与 year_of_birth 字段匹配的行。到目前为止,我的声明是这样写的:
select inp.year_of_birth, res.notes, res.result
from order_input inp join order_result res on inp.order_id = res.order_id
where res.result !='no match'
and res.notes like '%' + inp.year_of_birth + '%'
现在我收到一个错误 thta 说“将 varchar 值 '%' 转换为数据类型 int 时转换失败。我不确定我做错了什么,因为我正在使用类似的语句里面有这种类型的字符串可以工作...
最佳答案
您需要使用 CONCAT而不是 +
res.notes like CONCAT('%', inp.year_of_birth, '%')
关于MYSQL - 根据动态值选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16288584/