mysql check if numbers are in a comma separated list

前端 未结 7 1947
萌比男神i
萌比男神i 2020-11-27 06:13

I have a table like this:

UID(int) NUMBERS(blob)
----------------------
1        1,13,15,20
2        3,10,15,20
3        3,15

And I would l

7条回答
  •  醉梦人生
    2020-11-27 06:49

    Not the most pretty solution, but it works:

    select
       UID
    from
       YOUR_TABLE
    where
       find_in_set('3', cast(NUMBERS as char)) > 0
       and
       find_in_set('15', cast(NUMBERS as char)) > 0
    

    Note that it's string comparison, so you may need to cast your input parameters to char as well.

提交回复
热议问题