子选择查询中的表别名名称范围

时间:2014-11-18 19:51:25

标签: sql oracle

请查看下面的查询 - 我在下面的内部查询中收到无效的标识符t1.oid

我在oid

中有专栏iclr_request t1
select t1.requestNo 
     , t2.routeDistance,
     , ( 
         select WM_CONCAT(crc7) as "TravCirc7s" 
           from (
                  select (
                           select crc7 
                             from dim_afi_dnld_stn_v1 
                            where stn_sys_nbr = t3.stn_sys_nbr 
                              and rownum=1
                          ) as crc7 
                   from iclr_trav_circ7 t3 
                  where request_oid = **t1.oid** 
                    and sub_route_index=0 
                    and station_type_oid = 1 
                  order by sequence
                )
       ) 
  from iclr_request t1
     , iclr_summary_results t2
 where t1.oid = t2.request_oid

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

select t1.requestNo , t2.routeDistance,
       WM_CONCAT((select crc7 from dim_afi_dnld_stn_v1 where stn_sys_nbr = t3.stn_sys_nbr and rownum=1)) as "TravCirc7s" 
from iclr_request t1 
        join iclr_summary_results t2 on t1.oid = t2.request_oid
        left join iclr_trav_circ7 t3 on t3.request_oid = t1.oid 
                                        and t3.sub_route_index=0 
                                        and t3.station_type_oid = 1
group by t1.requestNo , t2.routeDistance;

相关的子查询可能只引用他们的父母1级以上(尽管一些Oracle文档说它是无限的)

编辑:它不会按WM_CONCAT中的顺序保存订单。您可能需要将其包装为父查询,然后包含wm_concat