表1
act_id
20
21
22
......
表2
sub_id exce act_id
2005 2006/2007 20
2006 2005/2007 20
2007 2005/2006 20
3001 3002/3003 21
3002 3001/3003 21
3003 3001/3002 21
.... ...... ..表一中的sub_id数目不定,但可通过act_id 得到
select sub_id from 表2 where act_id = 20exce 是一个字符串,现在就是想动态的得到这个exce字符串
初步想法是先得到相关的sub_id
select sub_id from 表2 where act_id = 表1.act_id
然后去掉自己的ID
组合其他sub_Id
id1/id3/
但是菜鸟,写不下去了?
PL\sql中,哪为大虾用D也可以.
act_id
20
21
22
......
表2
sub_id exce act_id
2005 2006/2007 20
2006 2005/2007 20
2007 2005/2006 20
3001 3002/3003 21
3002 3001/3003 21
3003 3001/3002 21
.... ...... ..表一中的sub_id数目不定,但可通过act_id 得到
select sub_id from 表2 where act_id = 20exce 是一个字符串,现在就是想动态的得到这个exce字符串
初步想法是先得到相关的sub_id
select sub_id from 表2 where act_id = 表1.act_id
然后去掉自己的ID
组合其他sub_Id
id1/id3/
但是菜鸟,写不下去了?
PL\sql中,哪为大虾用D也可以.
得到3个sub_id
用这3个sub_Id 组合成一个互斥字符串,自己不会更自己相斥.所以要取掉自己.
比如.
得到3个sub_Id
2005
2006
2007
那想对应的组合关系就是:
2005 2006/2007
2006 2005/2007
2007 2005/2006
http://community.csdn.net/Expert/topic/4161/4161213.xml?temp=.7113916
进行字符串连接。然后把每个记录的exce中的sub_Id部分替换为空。
select t.*,
(
select max(sys_connect_by_path(subject_id,'/')) result from
(select action_id,subject_id,rn,lead(rn) over(partition by action_id order by rn) rn1
from (select action_id,subject_id,row_number() over(order by action_id,subject_id desc) rn from df_sale_subject)
)
start with action_id = t.action_id and rn1 is null connect by rn1 = prior rn
) value
from (select distinct action_id from df_sale_subject where action_id = '2265') t结果:
2265 /54207/54208/54209/54210/54211我想要的是
2265 54208/54209/54210/54211 54207
2265 54207/54209/54210/54211 54208
2265 /5420754208/54210/54211 54209