表C_file,其中有个字段是spile,他存的是字符形式,例如:

id
spile
 1
2,10,11
 2
2,3,20,22
 3
1,6,8
 4  
5,6,1,9

 

select * from C_file where spile LIKE '%1%'

如果这样查询的话,会查询出ID为1、3、4,但正确的应该是3、4

那么这个SQL语句应该怎么写才正确的查询出1

正确方法:

select * from C_file where find_in_set(1,spile)

或者:

select * from C_file where instr(concat(',',spile,','),',1,')<>0;

 

相关文章:

  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-31
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案