解决方案 »

  1.   

    http://blog.csdn.net/acmain_chm/article/details/4142971
    MySQL中进行树状所有子节点的查询
    在Oracle 中我们知道有一个 Hierarchical Queries 通过CONNECT BY 我们可以方便的查了所有当前节点下的所有子节点。但很遗憾,在MySQL的目前版本中还没有对应的功能。 在MySQL中如果是有限的层次,比如我们事先如果可以确定这个树的最大深度是4, 那么所有节点为根的树的深度均不会超过4,则我们可以直接通过left join 来实现。 但很多时候我们...
      

  2.   

    直接按materilacode like '110%' 就行了。
      

  3.   

    mysql不支持递归查询。 
    如果预先知道最大深度的话可以使用union,比如下面认定最大深度为4:select * from a where id = ? or pid = ?
    union
    select * from a where pid  in (select id from a where pid  = ?)
    union
    select * from a where pid  in (select id from a where pid  in (select id from a where pid  = ?))?转入任意一个id, 可以查询id及其所有子记录。
      

  4.   

    4楼的兄弟,你的回答对我这个表可用,但是如果我这个表里面没有 materialcode 字段,就实现不了了。
      

  5.   

    说明,在 表 i_base_specification 表中有14万条数据。如果关联查询不关联 表i_base_specification,查询时间是0.006s,如果关联表查询的话就要12.876s,找高手优化一下sql