我想访问子查询中的st.Gr_number列 但这给了我错误
ORA-00904:“ ST”。“ GR_NUMBER”:无效的标识符
Select st.Gr_number,
st.STUDENT_ID, st.course,
st.Student_Name,cr.course_name,
st.Status as Active,
st.GR_NUMBER as Fee_Detail,
(Select sum(nvl(r.amt, 0)-nvl(f.fee_amount, 0)) as Current_Balance
from FEE_SCHEDULE f
full outer join (select gr_number, to_char(pmt_date,'yyyymm') pmt_month, sum(nvl(pmt_amount,0)) amt
from FEE_PAYMENT_POSTED
Where pmt_type = 'FEE'
and gr_number = st.Gr_number
group by gr_number, to_char(pmt_date,'yyyymm')
) r
on f.GR_NUMBER=r.GR_NUMBER and f.SCHEDULE_MONTH=r.pmt_month
where nvl(f.gr_number,r.gr_number) = st.Gr_number
) currentBalance
from student st inner join course cr on cr.course_id=st.course
where st.student_id=:P166_STUDENT_ID and upper(st.Status)='STUDYING';
答案 0 :(得分:0)
在内部查询中,您尝试使用st.GR_NUMBER
,但仍未定义它在外部查询中的使用。
这是问题所在的gr_number = st.Gr_number
。
答案 1 :(得分:0)
此行导致错误:
and gr_number = st.Gr_number
尽管很难从格式上分辨出来,但这嵌套了两个层次:
select . . . ,
(select . . .
from . . .
(select . . .
from . . . gr . . .
where . . . and
gr_number = st.Gr_number
) level3
) level2
from . . . st . . .
Oracle的范围规则仅允许将表引用识别为一级。因此,在level3
中,您可以引用level2
,但不能引用外部级别。
您有一个非常复杂的查询。没有办法知道这是否是唯一的问题,所以我什至不会尝试修复它。
我建议您通过简化查询问另一个问题。