如何使用数组中存储数据的where条件

how to use where condition from stored data in array

id | name | permission
1  | John | 1,4,3
2  | mike | 7,4,3
3  | sky  | 3,2,1

这是我的数据库

现在我可以使用 where 条件

获取select查询

例如select * 来自 friend where permission='4'

但我无法获取任何数据,那该怎么办?

请帮忙

Select * 来自朋友 FIND_IN_SET('4',permission);

您似乎将多个权限一起存储在一个字符串中。

对您来说,查询如下所示:

select * from friend where permission='4'

这意味着任何包含 4 的东西。 对于mysql,它看到:

select * from friend where permission= ONLY '4'
// Meaning the permissions column can ONLY CONTAIN 4.
// Also, ONLY is meant as a visual, don't use it in queries.

尝试:

find_in_set('4',permission) <> 0
// This means It needs to find number 4 and can't return 0 results.

查看这些以获取更多信息:

MySQL query finding values in a comma separated string

http://www.w3resource.com/mysql/string-functions/mysql-find_in_set-function.php

可以通过以下查询来完成:

select * from friend where permission like '%4%'