如:
一个字符串可能为a,b,c
也可能为b,c
也可能为c
数据表中fid字段存在多个a或b或c
如果字符中包含a,b,c,要查询出fid中fid为a或b或c的数据
如果字符中包含,b,c,要查询出fid中fid为b或c的数据
create table `tab` (
`fid` varchar(2) null default null,
`fname` varchar(10) null
)
collate='utf8_general_ci'
engine=innodb;
insert into `tab` (`fid`, `fname`) values
('a', 'a01'),
('a', 'a02'),
('a', 'a03'),
('a', 'a04'),
('b', 'b02'),
('b', 'b03'),
('b', 'b04'),
('b', 'b01'),
('b', 'b05'),
('c', 'c02'),
('c', 'c03'),
('c', 'c01');
回复讨论(解决方案)
假定你输入的串是(或经处理后)A,C,B 这样的格式,那么可以
严格匹配
select * from tab where find_in_set(fID, '$inp')
模糊匹配
select * from tab where '$inp' like concat('%‘, fID, '%')
感谢用xuzuning 的解答,用 find_in_set(fID, '$inp')解决了










