gpt4 book ai didi

php - mysql 对应 php 的 in_array

转载 作者:行者123 更新时间:2023-11-29 22:38:16 28 4
gpt4 key购买 nike

SELECT * FROM conversations WHERE chatMembers LIKE '%1%'AND chatMembers LIKE '%10%'

对话表

id | chatMembers | conversation
1 | 1^10 | .......
2 | 1^100 | .......
3 | 10^100 | .......

chatMembers 列包含该对话中涉及的用户 ID。我只想从对话表中选择 userId 为 1 和 10 的行,但上面的查询返回所有行,甚至包含 10 和 100 等的行。

我正在考虑一种与 php 的 in_array 相同但适用于字符串的方法。

最佳答案

当您在两侧使用 % 时,这意味着您正在选择字符串中同时包含 1 和 10 的任何行。因此 100 也包含 1 和 10(字符串格式),因此被选中。

SELECT * FROM conversations WHERE ( 
chatMembers LIKE '%^1^%'
OR
chatMembers LIKE '%^1'
OR
chatMembers LIKE '1^%' )
AND(
chatMembers LIKE '%^10^%'
OR
chatMembers LIKE '%^10'
OR
chatMembers LIKE '10^%' )

关于php - mysql 对应 php 的 in_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29466571/

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