mysql中in 做条件匹配 带逗号的字符串 数据异常解决
在数据库中表doctor中cancer字段存放着以逗号分隔的外键idselect cancer from doctor where id=1;
数据如下
cancer1,2,3
我需要在表cancer_type中匹配刚刚的外键,
于是用FIND_IN_SET函数:
select * from cancer_type c where FIND_IN_SET(c.cancer_id, (select cancer from doctor where id=1) )
数据如下
cancer_idcancer_namecancer_prefix1肺癌Lung2结直肠癌Col3胃癌Sto
用in来匹配却不行
select * from cancer_type where cancer_id in (select cancer from doctor where id=1)
数据如下:
cancer_idcancer_namecancer_prefix1肺癌Lung
页:
[1]