求救一个sql语句或者存储过程

happyct 2014-07-10 01:56:08
表记录:

1002
100201
1002018523532
100201435X46413
100202
1002026335332
2001
200101
200102


我现在需要得到哪些节点是分支节点,哪些是叶子节点。实际上:1002,100201,100202,2001是分支节点,其他都是叶子节点。可以肯定的是,同个父节点下的分支节点(非叶子节点)的长度是一样的。
...全文
156 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
happyct 2014-07-11
  • 打赏
  • 举报
回复
非常感谢,万分感谢。
  • 打赏
  • 举报
回复
引用 2 楼 zlloct 的回复:
[quote=引用 1 楼 happyct 的回复:] 如果可能的话,最好知道每个分支节点的层次。
1--非叶子 0-叶子节点 lvl为层次:


with t as
 (select '1002' c1
    from dual
  union all
  select '100201' c1
    from dual
  union all
  select '1002018523532' c1
    from dual
  union all
  select '100201435X46413' c1
    from dual
  union all
  select '100202' c1
    from dual
  union all
  select '1002026335332' c1
    from dual
  union all
  select '2001' c1
    from dual
  union all
  select '200101' c1
    from dual
  union all
  select '200102' c1
    from dual)
select t3.c1, t3.lvl, t4.is_leaf
  from (select t2.c1, count(1) lvl
          from t t1, t t2
         where t2.c1 like t1.c1 || '%'
         group by t2.c1
         order by t2.c1) t3,
       (select c1,
               decode((select count(*)
                        from t t2
                       where t2.c1 like t1.c1 || '%'
                         and t2.c1 <> t1.c1),
                      0,
                      0,
                      1) is_leaf
          from t t1) t4
 where t3.c1 = t4.c1;
[/quote] ++
CT_LXL 2014-07-10
  • 打赏
  • 举报
回复
引用 1 楼 happyct 的回复:
如果可能的话,最好知道每个分支节点的层次。
1--非叶子 0-叶子节点 lvl为层次:


with t as
 (select '1002' c1
    from dual
  union all
  select '100201' c1
    from dual
  union all
  select '1002018523532' c1
    from dual
  union all
  select '100201435X46413' c1
    from dual
  union all
  select '100202' c1
    from dual
  union all
  select '1002026335332' c1
    from dual
  union all
  select '2001' c1
    from dual
  union all
  select '200101' c1
    from dual
  union all
  select '200102' c1
    from dual)
select t3.c1, t3.lvl, t4.is_leaf
  from (select t2.c1, count(1) lvl
          from t t1, t t2
         where t2.c1 like t1.c1 || '%'
         group by t2.c1
         order by t2.c1) t3,
       (select c1,
               decode((select count(*)
                        from t t2
                       where t2.c1 like t1.c1 || '%'
                         and t2.c1 <> t1.c1),
                      0,
                      0,
                      1) is_leaf
          from t t1) t4
 where t3.c1 = t4.c1;
happyct 2014-07-10
  • 打赏
  • 举报
回复
如果可能的话,最好知道每个分支节点的层次。

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧