任何人都可以解释为什么我收到以下错误消息:
ORA-00904:" BPT"。" OBA_REQ_FK":无效标识符
sql可以正常工作,直到我把它放在我的连接中。
left outer join (Select *
From (SELECT OBA_REQ_FK, Max(CRE_DATE) AS CRE_DATE
FROM fmis.open_burn_requests_pt
GROUP BY OBA_REQ_FK) ptl
join
(SELECT OBA_REQ_FK, USNG_COORDS,CRE_DATE
FROM fmis.open_burn_requests_pt) ttl
on ttl.CRE_DATE = ptl.CRE_DATE) bpt on bpt.oba_req_fk = oba.pk
答案 0 :(得分:1)
问题在于子查询SELECT *
。
子查询上有两个列名ptl.oba_req_fk
和ttl.oba_req_fk
,外ON
不知道要使用哪一个
你需要确定你需要哪一个。
LEFT OUTER JOIN
(
SELECT -- * ptl.oba_req_fk,ttl.oba_req_fk
FROM (
SELECT oba_req_fk,
max(cre_date) AS cre_date
FROM fmis.open_burn_requests_pt
GROUP BY oba_req_fk) ptl
JOIN
(
SELECT oba_req_fk,
usng_coords,
cre_date
FROM fmis.open_burn_requests_pt) ttl
ON ttl.cre_date = ptl.cre_date
) bpt ON bpt.oba_req_fk = oba.pk
注意:
select *
请select
您需要的列这可以提高性能修改强>
我想你需要获得ptl.oba_req_fk
,因为你想获得最后的日期数据。
LEFT OUTER JOIN
(
SELECT ptl.oba_req_fk,
ptl.cre_date,
ttl.usng_coords
FROM (
SELECT oba_req_fk,
max(cre_date) AS cre_date
FROM fmis.open_burn_requests_pt
GROUP BY oba_req_fk) ptl
JOIN
(
SELECT oba_req_fk,
usng_coords,
cre_date
FROM fmis.open_burn_requests_pt) ttl
ON ttl.cre_date = ptl.cre_date
) bpt ON bpt.oba_req_fk = oba.pk
答案 1 :(得分:0)
好的,这就是我所做的,现在似乎可行了:
left outer join (Select *
From (SELECT OBA_REQ_FK, Max(CRE_DATE) AS CRE_DATE
FROM fmis.open_burn_requests_pt
GROUP BY OBA_REQ_FK) ptl
join
(SELECT OBA_REQ_FK as OBAREQFK, USNG_COORDS,CRE_DATE
FROM fmis.open_burn_requests_pt) ttl
on ttl.CRE_DATE = ptl.CRE_DATE) bpt on bpt.oba_req_fk = oba.pk