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.
这是我的小提琴。我的查询:
update foos set foo_id = ((SELECT max_foo_id FROM (SELECT MAX(foo_id) AS max_foo_id FROM foos) AS temp_foos) + 1) where foo_id is null;
为 foo_ids生成值1, 2, 2, 2(子查询只运行一次?)但我希望它给我1, 2, 3, 4
1, 2, 2, 2
1, 2, 3, 4
这个怎么样?
UPDATE foos a INNER JOIN ( SELECT a.bar_ID, @rn := @rn + 1 row_Num FROM foos a,(SELECT @rn := (SELECT MAX(foo_ID) FROM foos)) b WHERE a.foo_ID IS NULL ) b ON a.bar_ID = b.bar_ID SET a.foo_id = b.row_Num
更新 1