根据相同主键,合并其他字段值,形成一条记录(oracle)

将具有相同的主键INVT_PROD_ID值,其他列值CLAUSE_MEMO,CLAUSE_TP_CD,BBCK_DT使用||进行合并,形成一条记录:
select INVT_PROD_ID,
MAX(subStr(CLAUSE_MEMO, 3)) CLAUSE_MEMO,
MAX(subStr(CLAUSE_TP_CD, 3)) CLAUSE_TP_CD,
MAX(subStr(BBCK_DT, 3)) BBCK_DT
from (SELECT INVT_PROD_ID,
sys_connect_by_path(CLAUSE_MEMO, '' || '') CLAUSE_MEMO,
sys_connect_by_path(CLAUSE_TP_CD, '' || '') CLAUSE_TP_CD,
sys_connect_by_path(BBCK_DT, '' || '') BBCK_DT
FROM (SELECT INVT_PROD_ID,
CLAUSE_MEMO,
CLAUSE_TP_CD,
BBCK_DT,
INVT_PROD_ID || rn rchild,
INVT_PROD_ID || (rn - 1) rfather
FROM (SELECT INVT_PROD_ID,
CLAUSE_MEMO,
CLAUSE_TP_CD,
BBCK_DT,
row_number() over(PARTITION BY A.INVT_PROD_ID ORDER BY A.CLAUSE_TP_CD) rn
FROM (Select CLAUSE_MEMO,
CLAUSE_TP_CD,
BBCK_DT,
INVT_PROD_ID
From V_J_B_CLAUSE
where INVT_PROD_ID In
(Select INVT_PROD_ID
From V_J_B_CLAUSE
Group By INVT_PROD_ID
Having Count(*) > 1)) A) AA) AAA
CONNECT BY PRIOR rchild = rfather
START WITH rfather LIKE '' %0 '') AAAA
group by INVT_PROD_ID

union

Select to_char(INVT_PROD_ID),
to_char(CLAUSE_MEMO),
to_char(CLAUSE_TP_CD),
to_char(BBCK_DT)
From V_J_B_CLAUSE
where INVT_PROD_ID In (Select INVT_PROD_ID
From V_J_B_CLAUSE
Group By INVT_PROD_ID
Having Count(*) = 1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值