id cid name
185 183 新手指南
186 183 支付方式
187 185 注册会员
188 186 在线支付得到如下 查询 结果:id1 cid1 name1 id2 cid2 name2
187 185 注册会员 188 186 在线支付
谢谢  

解决方案 »

  1.   

    系统只能给到20分,问题解决了 再另开发份的帖子  呵呵  csnder  对分还是那么的关注
      

  2.   


    create table tb(ID varchar(10),cid varchar(10),name varchar(10))
    insert into tb
    select 185,183,'新手指南' union all
    select 186,183,'支付方式' union all
    select 187,185,'注册会员' union all
    select 188,186,'在线支付' 
    go
    select * into #tb1  from tb WHERE ID=187
    select *  into #tb2   from tb WHERE ID=188
    select A.ID,A.CID,A.NAME,B.ID AS ID2,B.CID AS CID2,B.NAME AS NAME2  FROM #TB1 A, #TB2 B
    DROP TABLE #TB1,#TB2
    DROP TABLE TB
    SELECT * FROM #TB1
      

  3.   

    create table tb(id int,cid int,name varchar(20))
    insert into tb select 185,183,'新手指南'
    insert into tb select 186,183,'支付方式'
    insert into tb select 187,185,'注册会员'
    insert into tb select 188,186,'在线支付'
    go
    select a.id as id1,a.cid as cid1,a.name as name1,d.id as id2,d.cid as cid2,d.name as name2
    from tb a inner join tb b on a.cid=b.id
    inner join tb c on b.cid=c.cid and b.id<>c.id
    inner join tb d on d.cid=c.id
    where a.name='注册会员'
    /*
    id1         cid1        name1                id2         cid2        name2
    ----------- ----------- -------------------- ----------- ----------- --------------------
    187         185         注册会员                 188         186         在线支付(1 行受影响)*/
    go
    drop table tb