2

我有一个表,对于表的一列,我需要null根据与同一个表的另一列再次匹配的值,将其值替换为另一列中的值。

意思是说我t1有主键表c1

  c1       c2         c3
--------------------------
1          a           null
23         b           null
2          c             1

所以我希望我的结果为:

  c1         c2            c3
------------------------------
1             a           null
23            b           null
2             c             a   ---->(means the  1 in column c3 is replaced by column c2's 
                                       value whose c1's value is 1)
4

2 回答 2

1

干得好:

update t1 set y.c3 = x.c2
from t1 x inner join t1 y on x.c1 = y.c3;
于 2013-07-27T05:16:32.660 回答
1

尝试这个:

SELECT t.c1,t.c2,(SELECT a.c2 FROM t1 a WHERE a.c1=t.c3) FROM t1 t
于 2013-07-27T07:59:44.157 回答