【发布时间】:2015-12-20 13:02:14
【问题描述】:
我有一个 sql 查询,它检索值是字符串的列。我想在它旁边创建一个列,如果值中包含子字符串“MB”,则值为 1,否则为 0
【问题讨论】:
-
你能提供你的代码吗..
我有一个 sql 查询,它检索值是字符串的列。我想在它旁边创建一个列,如果值中包含子字符串“MB”,则值为 1,否则为 0
【问题讨论】:
你可以用case when then 这样试试:
select case when INSTR('mycol', 'MB') > 0 then 1
else 0
end as myBoolCol
【讨论】:
pos和len?
'MB' 字符串的。
select column,
case when column like '%mb%' then 1
else 0 end
from table
这适用于 MSSQL 和 MYSQL
【讨论】: