- 论坛徽章:
- 0
|
-- create table recursion
-- (
-- id int ,
-- action varchar(100)
-- );
--
-- delete from recursion ;
-- insert into recursion values(1,'a');
-- insert into recursion values(1,'b');
-- insert into recursion values(2,'c');
-- insert into recursion values(2,'d');
-- insert into recursion values(1,'e');
-- insert into recursion values(2,'f');
with x(id,action,t1,t2) as
(
select id,action ,t1,t2 from (select id ,action ,rownumber()over(partition by id) t1 ,rownumber()over(partition by id) t2 from recursion ) a
where t1=1 and t2=1
union all
select x.id,x.action||'-'||b.action,x.t1+1,x.t2
from x , (select id ,action ,rownumber()over(partition by id) t1 ,rownumber()over(partition by id) t2 from recursion ) b where b.id=x.id and x.t1=b.t2-1
)
select * from x where t1=3;
where t1=3; 这块的3可以搞个子查询。你自己写吧 |
|