解决方案 »

  1.   

    ;with f as 
    (
    select * from tb where id=xx
    union all
    select a.* from tb as a inner join f as b on a.parentid=b.id
    )select * from f
      

  2.   

    额。。关联的第二张表的count字段内容没有啊
      

  3.   

    可能我没说明白,第一张表的id 就是 第二张表的cid  
      

  4.   

    ;with f as 
    (
    select * from tb1 where id=xx
    union all
    select a.* from tb1 as a inner join f as b on a.parentid=b.id
    )
     
    select * from f  as a inner join tb2 as b on a.id=b.cid
      

  5.   

    思路:使用CTE的递归 求树的上级或者下级