MySQL:使用FIND_IN_SET(str,strlist)
SELECT col1, col2, ... FROM my_table
WHERE FIND_IN_SET(value_to_find, NeedGroupIds);
/** if found, find_in_set should result in a number > zero **/
示例 1:
SELECT FIND_IN_SET( 6, ',5,6,7,' ); -- results 3
SELECT FIND_IN_SET( '7', ',5,6,7,' ); -- results 4
SELECT FIND_IN_SET( '8', ',5,6,7,' ); -- results 0
MsSQL:使用LIKE (Transact-SQL)
/** For non-mysql databases, an alternate to FIND_IN_SET **/
SELECT col1, col2, ... FROM my_table
WHERE ',' + NeedGroupIds + ',' LIKE '%,12,%';
示例 2:
/** this should result `Markers` **/
SELECT col1, col2, ... FROM my_table
WHERE ',' + NeedGroupIds + ',' LIKE '%,12,15,%';
/** this should result `Markers` and `intel` **/
SELECT col1, col2, ... FROM my_table
WHERE ',' + NeedGroupIds + ',' LIKE '%,12,%';
/** this should result `Pen` and `cello` **/
SELECT col1, col2, ... FROM my_table
WHERE ',' + NeedGroupIds + ',' LIKE '%,2,%';
参考:Alternate to FIND_IN_SET for non-MySQL databases