I have a row in my sql table that look like this

I would like to run query with find_in_set like this:

list
------------
1,2,5,33,3,4

SELECT * FROM mytable WHERE FIND_IN_SET( id, list ) 

and get the position of the result in a new field

有帮助吗?

解决方案

FIND_IN_SET() returns the position of the id value in the list, so:

SELECT *,
       FIND_IN_SET( id, list ) as position
  FROM mytable 
 WHERE FIND_IN_SET( id, list )

or

SELECT *,
       FIND_IN_SET( id, list ) as position
  FROM mytable 
 HAVING position > 0
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top