如:
一个字符串可能为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')解决了
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号