首页 新闻 赞助 找找看

sql 递归 with 问题

0
悬赏园豆:10 [已关闭问题] 关闭于 2015-08-06 14:25

现在有数据库有
parent  body

              a

  a          aa

  aa        aaa1

 aa         aaa2

 aa          null

这种数据结构 现在想转换成

a    aa    aaa1

a    aa    aaa2

a    aa     null  这种结构  求大虾给个语句

差生的主页 差生 | 初学一级 | 园豆:3
提问于:2015-08-06 12:19
< >
分享
所有回答(1)
0

 with cte as
 (
    select parent,body from table1 where parent = ""
    union all
    select t.parent,t.body from cte c inner join table1 t
    on c.body = w.parent
 )
 select a.parent,a.body,b.body from cte a
 left join cte b on a.body = b.parent
 left join cte c on b.body = c.parent
 where a.parent=""

at小怪兽 | 园豆:760 (小虾三级) | 2015-08-06 17:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册