分組遞增的值更新表我有一個自我引用表在MySQL與
Posts
postId
FK_PostId
idx
的IDX值目前0,但我需要更新他們讓每一個有帖子ID每FK_PostId的遞增值。簡單地說,但非功能寫成
update idx = idx + 1 where FK_PostId is not null order by postId group by FK_PostID
期望的結果
postId 15 FK_PostId 4 idx 0
postId 16 FK_PostId 4 idx 1
postId 17 FK_PostId 4 idx 2
postId 18 FK_PostId 4 idx 3
postId 24 FK_PostId 4 idx 4
postId 32 FK_PostId 50 idx 0
postId 35 FK_PostId 50 idx 1
我似乎無法扎堆智能查詢此。 任何人都可以幫我嗎?
請張貼以前的數據,以便我們能夠看到你'的頻15/4/0 ...' – fedorqui 2013-03-07 15:48:20