我在嵌套查询中收到错误。我试图通过给它一个别名并在子查询中调用它来从父查询中选择id。如何从mytable外部查询中获取id?
SELECT * FROM mytable t
WHERE (
SELECT count(*) number_of_weekdays FROM
(
SELECT start_date, to_char(start_date+(level-1), 'fmday') d_day
FROM ( select strt_dt as start_date , trunc(sysdate) as end_date from mytable where id = t.id )
connect by level <= end_date - start_date + 2
)
WHERE d_day IN (
select rtrim(ltrim(regexp_substr(intv,'[^,]+', 1, level))) from ( select intv from mytable where id = t.id )
connect by regexp_substr(intv, '[^,]+', 1, level) is not null
)
) <= col1
专栏我主要关注:
INTV | STRT_DT
--------------------------------------------------
3, monday, tuesday, thursday, sunday | 07-MAY-18
ERROR:
ORA-00904: "T"."ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
答案 0 :(得分:0)
从子查询中,您只能引用直接外部查询的数据。您无法跨多个级别的查询和子查询访问数据。
在您的情况下,您有三个级别的子查询,即总共四个级别,并且您尝试从最里面的查询访问最外层查询的数据。