行列互换

涉及表:
rpt_1(
id,
relatioship1 ,
related_cust_id1 ,
relatioship2 ,
related_cust_id2 ,
relatioship3 ,
related_cust_id3 ,
relatioship4 ,
related_cust_id4 ,
relatioship5 ,
related_cust_id5 ,
relatioship6 ,
related_cust_id6 ,
relatioship7 ,
related_cust_id7 ,
relatioship8 ,
related_cust_id8 ,
relatioship9 ,
related_cust_id9 ,
relatioship10 ,
related_cust_id10,
relatioship11 ,
related_cust_id11,
relatioship12 ,
related_cust_id12,
relatioship13 ,
related_cust_id13,
relatioship14 ,
related_cust_id14,
relatioship15 ,
related_cust_id15
)
obj_abc(
id,
code,
name
)
需实现的结果:rpt_1表连(id)obj_abc表用code,name字段填充rpt_1的relatioship,related_cust_id字段,无值为null;id为rpt_1表主键,在表obj_abc中一个id下有N(N<=15)个code,name.
实现方法:
update rpt_1 rpt
set (rpt.relatioship1 ,
rpt.related_cust_id1 ,
rpt.relatioship2 ,
rpt.related_cust_id2 ,
rpt.relatioship3 ,
rpt.related_cust_id3 ,
rpt.relatioship4 ,
rpt.related_cust_id4 ,
rpt.relatioship5 ,
rpt.related_cust_id5 ,
rpt.relatioship6 ,
rpt.related_cust_id6 ,
rpt.relatioship7 ,
rpt.related_cust_id7 ,
rpt.relatioship8 ,
rpt.related_cust_id8 ,
rpt.relatioship9 ,
rpt.related_cust_id9 ,
rpt.relatioship10 ,
rpt.related_cust_id10,
rpt.relatioship11 ,
rpt.related_cust_id11,
rpt.relatioship12 ,
rpt.related_cust_id12,
rpt.relatioship13 ,
rpt.related_cust_id13,
rpt.relatioship14 ,
rpt.related_cust_id14,
rpt.relatioship15 ,
rpt.related_cust_id15) =
(select max(case when ron=1 then code end),
max(case when ron=1 then name end),
max(case when ron=2 then code end),
max(case when ron=2 then name end),
max(case when ron=3 then code end),
max(case when ron=3 then name end),
max(case when ron=4 then code end),
max(case when ron=4 then name end),
max(case when ron=5 then code end),
max(case when ron=5 then name end),
max(case when ron=6 then code end),
max(case when ron=6 then name end),
max(case when ron=7 then code end),
max(case when ron=7 then name end),
max(case when ron=8 then code end),
max(case when ron=8 then name end),
max(case when ron=9 then code end),
max(case when ron=9 then name end),
max(case when ron=10 then code end),
max(case when ron=10 then name end),
max(case when ron=11 then code end),
max(case when ron=11 then name end),
max(case when ron=12 then code end),
max(case when ron=12 then name end),
max(case when ron=13 then code end),
max(case when ron=13 then name end),
max(case when ron=14 then code end),
max(case when ron=14 then name end),
max(case when ron=15 then code end),
max(case when ron=15 then name end)
from (select id,code,name, row_number() over(partition by id order by code) ron from obj_abc) tmp
where tmp.id = rpt.id
);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值