提取分配给用户ID列表的ID [英] extracting the ids assigned to a list of user ids

查看:93
本文介绍了提取分配给用户ID列表的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以上问题可能令人困惑,所以让我解释一下.我有一个表,其结构类似于以下内容:

Above question may be confusing so let me explain it. I have a table with structure similar as below :

form_id         bank_ids 

   1            5,6,7,8
   2            7,10
   3            4,7,9
   4            5,8,1

现在假设我要提取分配给bank_id 7的表单ID,如何提取它?

Now suppose I want to extract the form ids assigned to bank_id 7, how can I able to extract it?

推荐答案

MySQL具有一个名为

MySQL has a builtin function for that called FIND_IN_SET.

SELECT *
FROM tableName
WHERE FIND_IN_SET('7', bank_ids) > 0

您应该正确规范化您的表.

You should properly normalize your table.

更新

如果要使用LIKE,则需要在两侧连接,.例如

if you want to use LIKE, you need to concatenate , on both side. eg

WHERE CONCAT(',', bank_ids, ',') LIKE CONCAT('%,', '7', ',%')

这篇关于提取分配给用户ID列表的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆