MySQLに自己参照テーブルがあります
Posts
postId
FK_PostId
idx
idx値は現在0ですが、すべてのpostIdが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
私はこれについて賢い質問をまとめることができないようです。誰かが私を助けることができますか?