这是我的表结构。
我有一个像
这样的查询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,
答案 0 :(得分:0)
如果可能,您可以将查询重写为
SELECT `user_pid` ,'%,33,%' from `table` WHERE
`upchain` LIKE '%,33,%'
union all
SELECT `user_pid` ,'%,52,%' from `table` WHERE
`upchain` LIKE '%,52,%'
您还可以使用case
答案 1 :(得分:0)
尝试使用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,%'
:
{{1}}
答案 2 :(得分:0)
SELECT
user_pid,
IF( upchain LIKE '%,33,%', '%,33,% condition' ,
IF(
upchain like '%,52,%', '%,52,% condition',
IF(
upchain like '%,98,%', '%,98,% condition',
'other condition'
)
)
)
as condition from table
您可以使用此语法并根据需要添加多个条件。
IF('your condition', << true part >>, "another condition OR elase part")