How can I search within a table of comma-separated values?

前端 未结 6 1943
小蘑菇
小蘑菇 2020-12-10 00:25

I have a MySQL table which contains comma-separated values like this:

first row=(3,56,78,12)  
second row=(6,44,2,3)  
third row=(67,4,2,7,1)  
fourth row=(8         


        
6条回答
  •  不知归路
    2020-12-10 00:46

    Just Use Mysql Function FIND_IN_SET(str,strlist) .

    Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings. A string list is a string composed of substrings separated by “,” characters. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit arithmetic. Returns 0 if str is not in strlist or if strlist is the empty string. Returns NULL if either argument is NULL. This function does not work properly if the first argument contains a comma (“,”) character.

     SELECT * FROM table_name WHERE FIND_IN_SET('3', column_name);
    

提交回复
热议问题