我的sql表中有一行看起来像这样
我想用find_in_set运行查询:
list
------------
1,2,5,33,3,4
SELECT * FROM mytable WHERE FIND_IN_SET( id, list )
并将结果的位置放在新字段中
答案 0 :(得分:1)
FIND_IN_SET()返回列表中id值的位置,所以:
SELECT *,
FIND_IN_SET( id, list ) as position
FROM mytable
WHERE FIND_IN_SET( id, list )
或
SELECT *,
FIND_IN_SET( id, list ) as position
FROM mytable
HAVING position > 0