gpt4 book ai didi

mysql - 搜索查询以将字符串中的特定单词与 mysql 中的另一个字符串的值进行比较

转载 作者:行者123 更新时间:2023-11-29 05:29:09 24 4
gpt4 key购买 nike

我正在制作一个搜索模块,我需要在其中搜索与其他用户详细信息相匹配的用户详细信息,因为我需要比较用户详细信息。对于 agegender 等详细信息,我使用了 like '%search_term%' 并能够得到我想要的结果,但我没有能够查询详细信息,例如用户 1 说 english,french,spanish,因此它存储在数据库中,就像用逗号分隔的单词一样作为相同的标记。并假设其他用户只有一种共同语言 latin,hindi,french 即共同法语,那么如何根据用户 1 的详细信息过滤该用户,因为他/她仍然有一些共同点。以下查询是针对正常值,例如年龄

select * from users_profile 
where age like '%$search_term%'
order by created_time DESC

如何使用 AND 在此查询中进行查询并获得结果?

最佳答案

您可以进行自联接,然后将其中一个中的逗号替换为竖线,然后将该正则表达式与 rlike 一起使用。性能可能很糟糕。

select users_profile.*, users_profile2.id as other_id, 
users_profile2.language as other_lang from users_profile
inner join users_profile as users_profile2 on
users_profile.language rlike
replace(users_profile2.language,",","|")
and users_profile.id != users_profile2.id;

你可以自己看看: http://sqlfiddle.com/#!2/9549f/6

关于mysql - 搜索查询以将字符串中的特定单词与 mysql 中的另一个字符串的值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560264/

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