oracle子查询为游标结果集,这个SQL怎么破?select后的爬树子查询(connect by)变换
t_cum_info表有字段cust_code,prtn_id, t_pnm_partner 表有prtn_id(商户ID), parent_id(上线商户ID), partn_type字段。
样例数据
cust_code prtn_id
-------------- -------------
101 1
102 2
103 3
104 4
105 5
106 6
107 7
108 8
prtn_id parent_id partn_type
------------ ------------- ---------------
1 2 PT101
2 3 PT101
3 4 PT403
4 0 PT503
5 6 PT101
6 7 PT101
7 8 PT403
8 0 PT503
--希望获取到每个非PT403类型的商户的cust_code和商户对应的顶层商户ID
cust_code prtn_id
-------------- --------------
101 3
102 3
105 7
106 7
--原查询语句如下,但我希望不要把子查询放在select后(要建物化视图),而是放在where或from后
怎么破?感谢!
select i.cust_code,
(select max(p.prtn_id)
from t_pnm_partner p
where p.prtn_type = 'PT403'
start with p.prtn_id = i.prtn_id
connect BY nocycle prior p.parent_id = p.prtn_id) as father
from t_cum_info i
WHERE i.prtn_id not in
(select p.prtn_id
from t_pnm_partner p
where p.prtn_type = 'PT403');
总结
以上是生活随笔为你收集整理的oracle子查询为游标结果集,这个SQL怎么破?select后的爬树子查询(connect by)变换的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 宝马740废气阀更换多少钱?
- 下一篇: oracle 存储过程字符替换,Orac