一个困惑人的问题,请教sql脚本怎么写

happyct 2014-07-10 02:34:21
表记录:

1002
100201
1002018523532
100201435X46413
100202
1002026335332
2001
200101
200102


我现在需要得到哪些节点是分支节点,哪些是叶子节点。实际上:1002,100201,100202,2001是分支节点,其他都是叶子节点。可以肯定的是,同个父节点下的分支节点(非叶子节点)的长度是一样的。
...全文
101 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
happyct 2014-07-11
  • 打赏
  • 举报
回复
感谢。。。。。。
CT_LXL 2014-07-10
  • 打赏
  • 举报
回复
引用 楼主 happyct 的回复:
表记录: 1002 100201 1002018523532 100201435X46413 100202 1002026335332 2001 200101 200102 我现在需要得到哪些节点是分支节点,哪些是叶子节点。实际上:1002,100201,100202,2001是分支节点,其他都是叶子节点。可以肯定的是,同个父节点下的分支节点(非叶子节点)的长度是一样的。
0--叶子节点 1--非叶子节点

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 c1,
       decode((select count(*)
                from t t2
               where t2.c1 like t1.c1 || '%'
                 and t2.c1 <> t1.c1),
              0,
              0,
              1)
  from t t1;

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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