zoukankan      html  css  js  c++  java
  • 查找父类下的所有子类

     create   function   f_child(@pid   int)   
      
    returns   @re   table(id   int,l int)   
      
    as   
      
    begin   
      
    declare   @l   int   
      
    set   @l=0   
      
    insert   @re   select   id,@l   from   category   where  parentid=@pid   
      
    while   @@rowcount>0   
      
    begin   
      
    set   @l=@l+1   
      
    insert   @re   select   a.id,@l   
      
    from   category   a   join   @re   b   on   a.parentid=b.id   
      
    where   b.l=@l-1   
      
    end   
      
    return   
      
    end


    /*调用 查找父类为1 的所有子类*/
    select id from f_child(1)

  • 相关阅读:
    bzoj1098 1301
    bzoj3237
    bzoj3170
    bzoj4008
    一些题解
    bzoj4028
    bzoj3196
    redis学习
    quartz学习
    电商618 压测、优化、降级预案
  • 原文地址:https://www.cnblogs.com/yiki/p/723904.html
Copyright © 2011-2022 走看看