有一个父子结构的数据表
只知道id  如何查询这个id是第几级的??
谢谢

解决方案 »

  1.   

    select t1.id,t2.id...from tbname t1,tbname t2 where t2.id=t1.id这种格式 给表起两个别名 看看查询的结果 哪个对应哪个
      

  2.   

    ls的能不能说明白点
    我还是不太理解
    我现在只知道一个id
    怎么根据这个id得到他所在的层级??
      

  3.   

    你不是说父类的id也在同一张表中吗?
    难道你不知道这张表有哪些字段?
    describe tbname;
    得出你的表字段你还是查看一下 最好贴上来
    我也听迷糊了
      

  4.   

    一句SQL是没办法的用程序第归查询吧.int i=0;
    while (parentid is not null)
    {
    parentid = select parentid from yourTable where id=parentid;
    i++;
    }
    == 思想重于技巧 ==
      

  5.   

    表结构如下 类似这样
    id parentid name
    1     0      'a'
    2     1      'b'
    3     1      'c'
    4     2      'd'比如我传入id=4
    想得到是级别为 第3层一个sql语句能查出来吗
    还是需要写递归程序?
      

  6.   

    mySql, 一个sql语句
    没办法需要写程序
    == 思想重于技巧 ==