Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将某些行中的字段设置为序列中的数字(0、1、2、...)。通常这应该有效:
SET @counter:=-1; UPDATE nodes SET sort=@counter:=@counter+1 WHERE parent_id=2
但是无法使用 mysql_query() 进行多个查询。有没有办法在单个查询中完成此操作,或者我应该在一个循环中运行多个查询?
尝试加入:
UPDATE nodes cross join (select @counter := -1) const SET sort = (@counter:=@counter + 1) WHERE parent_id = 2;