对于以下查询,我收到以下错误。
ORA-00904: "BKG_ITEM"."ITEM_NO": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 11 Column: 60
似乎 BKG_ITEM 和 BKG 没有被内部子句标识。我在这里错过了什么,有没有办法做我想做的事情?(我正在尝试使用 WITH 子句优化查询)
select main_query.*
, RANK() OVER ( ORDER BY booking_id, product_code, item_no ) AS RNK
from
(select bkg_item.*,
(
CASE (bkg_item.product_code)
WHEN ( 'TOU' ) THEN
(
WITH rtb_dep_loc as ( select departure_location from res_tour_booking rtb
where rtb.booking_id = bkg_item.booking_id
and rtb.item_no = bkg_item.item_no
and rtb.product_code = 'TOU'
and rownum = 1
)
select city.name name from city
inner join location lc on lc.city = city.code
inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location
union
select city.name name from city
inner join airport lc on lc.city = city.code
inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location
union
select city.name name from city
inner join supplier lc on lc.city = city.code
inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location
)
else ''
end
) as city
from
(select rb.* from res_booking rb where rb.booking_id > 0 ) bkg
inner join
(select rbi.* from res_booking_item rbi where rbi.booking_id > 0 and rbi.product_code not in ( 'OWA' ) ) bkg_item
on bkg_item.booking_id = bkg.booking_id
)main_query;
先感谢您!