表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;
?