PostgreSQL表中的层次结构

用户名

我有一个包含以下结构的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中。

柯林·哈特

您的意思是:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章