select id,name from 表1 where id>=X

解决方案 »

  1.   

    和sign没关系吗?
    如果没有
    select * from tb where id >= 3
      

  2.   

    1、2、3楼的方法我曾想过。
    但要知道用自增id取值考虑到一个问题.就是关联id不一定按照我说的进行规则写出
    例如:
    id       name     sign 
    1         a           0 
    2         b           1   
    3         c           1   
    4         d           11 
    5         e           3 
    6         f           5 通过 select   *   from   tb   where   id   > =   3 而其中11       XX           0 关联的是 1 a 0 
    7         g           6 
    。。
    。。
    。。
    11       XX           0
      

  3.   

    难道sql 无法实现吗?
    看来真要从程序入手了。
      

  4.   


    Create table T (id int,name varchar(10),[sign] int)
    insert into T select 1,'a',0
    insert into T select 2,'b',1
    insert into T select 3,'c',1
    insert into T select 4,'d',3
    insert into T select 5,'e',3
    insert into T select 6,'f',5
    insert into T select 7,'g',6
    GoCreate function  f_cid(@id int)
    returns @t table(id int,level int)
    as
    begin
    declare @level int
    set @level=1
    insert into @t select @id,@level
    while @@rowcount>0
    begin
      set @level=@level+1
      insert into @t select a.[id],@level
      from T a,@t b
      where a.[sign]=b.[id]
      and b.level=@level-1
    end
    return
    endGOselect A.id,name  from dbo.f_cid(3) as  A,T
    where A.id=T.id
    /*
    id    name
    --------------
    3 c
    4 d
    5 e
    6 f
    7 g*/
    drop table T
    drop function dbo.f_cid
      

  5.   

    哦,对了 我用的oracle。oracle没有自增id,用的存储过程.
    所以自增id没有规则,通过自增id来实现  有些不妥
      

  6.   

    忘了加一句,oracle不知道支不支持上面的那個function。
    至于lz講的子增id,跟那個function沒關系
      

  7.   

    哦了,你那条sql 够我消化一段时间了.
          
       现在揭贴