sql - FIND_IN_SET question or -


Can anyone help me with mysql question? I have a list of items such as: '1', '2', '3', '4', '5', '6', '7', '8', '9' <3 > 3 to 3 elements set .. Now how can I find it with FIND_IN_SET above '4' and what set can it return from? In that case, let me tell you that from set 2 to

  SELECT FIND_IN_SET ('' '4' '', REPLACE (`some`, '', '')) `Where one with` id` = 2  

this gives me the position back .. But now, I have to return several sets from where 4 comes

1 ',' 2 ',' 3 'is a set,' 4 ',' 5 ',' 6 'second and' 7 ',' 8 ',' 9 'is the last

You can always use the integer division on the result of FIND_IN_SET, assuming that your set is always the length of 3 (but remember this one-base You need to adjust for this):

  (x - 1) div 3 + 1  

Then you get the expression:

/ P>
  (FIND_IN_SET ('' 4 '' ', REPLACE (`some`,' ',' ')) - 1) DIV 3 + 1  

Note that this is now 1 for the return elements instead of 0 which is not found if it is a problem, then you can examine it separately for this matter or use this expression instead:

  (FIND_IN_SET ('' '4' '', REPLACE (`some`, '', '')) + 2) DIV 3  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -