0

次の構造を含む PostgreSQL テーブルがあります。

Parent     child1     child2
1          10         12
2          13         
3

私がしたい:

 Parent     child1     child2
    1          10         12
    2          13         13
    3          3          3

つまり、child2 が NULL の場合、child1 を child2 に複製したいということです。child1 が null の場合、親を child1 と child2 に複製します。

4

1 に答える 1

1

次のような意味ですか。

select Parent,
       coalesce(child1, Parent) as child1,
       coalesce(child2, child1, Parent) as child2
from <tablename>;

?

于 2013-09-25T09:19:28.303 に答える