gpt4 book ai didi

php - SQL Select 查询 where column like string with and without spaces

转载 作者:行者123 更新时间:2023-12-02 17:38:17 24 4
gpt4 key购买 nike

我在 PHP 中有一个 SQL Select 查询,我需要在表中查找行,其中列就像一个带空格和不带空格的字符串

例如,如果我在数据库中的值为 ABC 123 并且我搜索 ABC123,查询将是

$sql = SELECT * from table where col_name LIKE '%ABC123%' ";

但我需要它返回 col_name 等于 ABC 123 的行

反之亦然,例如,如果数据库值为 123ABC 并且我搜索 123 ABC,查询将是

$sql = SELECT * from table where col_name LIKE '%123 ABC%' ";

我需要它返回 col_name 等于 123ABC

的行

最佳答案

$sql = SELECT * from table where REPLACE(col_name,' ','') LIKE '%ABC123%' ";

关于php - SQL Select 查询 where column like string with and without spaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24066221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com