在数据库中表doctor中cancer字段存放着以逗号分隔的外键id

select cancer from doctor where id=1;  

 

数据如下:

cancer
1,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_id cancer_name cancer_prefix
1 肺癌 Lung
2 结直肠癌 Col
3 胃癌 Sto







用in来匹配却不行

select * from cancer_type where cancer_id in (select cancer from doctor where id=1)  


数据如下:

cancer_id cancer_name cancer_prefix
1 肺癌 Lung

 

https://www.iteye.com/blog/fengjianrong-2218577


相关文章:

  • 2021-08-12
  • 2021-08-04
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-11-15
  • 2021-04-14
相关资源
相似解决方案