I have an sql query that retrieves a column which values are strings. I want to create a column next to it that takes a value of 1 if the substring 'MB' is contained in the value or 0 otherwise
You can try it using the case when then like this:
select case when INSTR('mycol', 'MB') > 0 then 1
else 0
end as myBoolCol
select column,
case when column like '%mb%' then 1
else 0 end
from table
This works for both MSSQL and MYSQL
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.