mysql - Setting order/position - resetting by two vars -


I want to ask that it can only be done by MySQL and not by php code

my I have a table that contains

  id, catid, order   

I know that

  SET @ pos: = 0; Update products SET order = @pos: = @ pin 1 order order;   

But how do I reset it (starting at 0 on each cadet).

I can choose each cat in php and can run different SQL each time.

"post-text" itemprop = "text">

Introduce a new variable @cat, compare with Catid and reset @pos on the cached changes

  SET @pos: = 0; SET @cat: = 0; Enter Product P (Choose ID, @pos: = if (cat cat> 0, @ pos + 1) as new_order, order by product ORDER from @cat: = catid) p2 p Id = p2 Id set order = p2.new_order;    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -