-2

我有一个名称为 Posts 的表,如下所示:

ID    ID_parent     type     ID_parent_old    ID_old
11         0        topic          0            1
22         0        topic          0            2
33         0        topic          0            3
44         0        reply          1            0
55         0        reply          2            0
...        ...      ...           ...          ...

更新后我会有类似的东西:

ID    ID_parent     type     ID_parent_old    ID_old
11         0        topic          0            1
22         0        topic          0            2
33         0        topic          0            3
44         11       reply          1            0
55         22       reply          2            0
...        ...      ...           ...          ...

那么,该怎么做呢?非常感谢。

4

1 回答 1

2

如果我理解你,这就是你需要的:

UPDATE Posts p1, Posts p2 
SET p1.ID_parent = p2.ID 
WHERE p1.type = 'reply' 
AND p2.type='topic'
AND p1.ID_parent_old = p2.ID_old
于 2013-10-23T11:44:11.137 回答