MYSQL:返回与多个搜索条件匹配的内容

MYSQL:返回与多个搜索条件匹配的内容,mysql,Mysql,这是我的桌子结构 我有一个疑问 SELECT `user_pid` from `table` WHERE `upchain` LIKE '%,33,%' OR `upchain` LIKE '%,52,%' OR upchain LIKE '%,98,%' 结果如下: 但我需要知道哪一行符合哪一个搜索条件。 有没有办法得到以下结果: user_pid | search_critetis -------------------------- 33 | ,33, 52

这是我的桌子结构

我有一个疑问

SELECT `user_pid` from `table` WHERE 
`upchain` LIKE '%,33,%' OR `upchain` LIKE '%,52,%' OR upchain LIKE '%,98,%'
结果如下:

但我需要知道哪一行符合哪一个搜索条件。 有没有办法得到以下结果:

user_pid | search_critetis
--------------------------
  33     |    ,33,
  52     |    ,52,
  98     |    ,98,
  100    |    ,98,
  101    |    ,98,

如果可能,您可以将查询重写为

SELECT `user_pid` ,'%,33,%' from `table` WHERE 
`upchain` LIKE '%,33,%' 
 union all
SELECT `user_pid` ,'%,52,%' from `table` WHERE 
 `upchain` LIKE '%,52,%' 

您还可以使用
case
重写查询,在下列情况下尝试使用
case

SELECT user_pid, 
       CASE WHEN upchain LIKE '%,33,%' THEN ',33,' ELSE
       CASE WHEN upchain LIKE '%,52,%' THEN ',52,' ELSE
       CASE WHEN upchain LIKE '%,98,%' THEN ',98,' END END END as upchain
FROM table
WHERE upchain LIKE '%,33,%' OR upchain LIKE '%,52,%' OR upchain LIKE '%,98,%'
您可以使用此语法并根据需要添加多个条件

IF('your condition', << true part >>, "another condition OR elase part")
IF('your condition',>,“其他条件或弹性部分”)

你真的应该改变你的桌子设计。切勿将多个值存储在一个文件中column@juergend:是的,我知道。我必须为一个特定的任务创建这个表。这不是我的主表。@kadamb我们能解决这个问题吗?
IF('your condition', << true part >>, "another condition OR elase part")