日期:2014-05-18 浏览次数:20668 次
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