为什么我不能使用子查询因式分解子句导致 where 子句,如下面的 sql 所示:
with rpt as(
select * from reports where caseid =
:case_id and rownum=1 order by created desc
)
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
where
rt.reportid = rpt.id
and
tg.gene not in('TMB','MS')
rpt
子查询在 select 语句的 where 子句中命名和使用。执行时遇到以下错误:ORA-00904: "RPT"."ID": invalid identifier
更新:
事实上,对同一事物的嵌套查询也给了我同样的问题。嵌套子查询仅从单行返回单列值:
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
where
rt.reportid = (select id from reports where caseid = :case_id and
rownum=1 order by created desc)
and
tg.gene not in('TMB','MS')