今天在写SQL时遇到一个问题,即sql内联视图子查询中的where条件中无法引用最外层查询结果数据。简化的sql语句如下:selectst.rowguid,(selectcount(*)from(selectt.idfromrats.ttspl0...
今天在写SQL时遇到一个问题,即sql内联视图子查询中的where条件中无法引用最外层查询结果数据。简化的sql语句如下:
select st.rowguid,
(
select count(*) from
(
select t.id from rats.ttspl02 t
where t.from_st_guid=st.rowguid //此处oracle报错
group by t.id
having count(t.id)>1
)
) as num
from rats.ttsbs01 st
运行SQL后,oracle在第6行【 where t.from_st_guid=st.rowguid】报ORA-00904:'ST'.'ROWGUID'标示符无效。
难道在子查询【select count(*) from……】中嵌套的内联视图子查询【select t.id from rats.ttspl02 t where……】中无法引用到最外层的查询结果数据【st.rowguid】?
还请高手指教!
我觉得不全是这样。
目前是3层查询,如果改成2层查询,那么子查询过程中就可以引用到父查询结果。比如SQL:
select st.rowguid,
(
select t.id from rats.ttspl02 t
where t.from_st_guid=st.rowguid //此处可以应用到父查询数据“st.rowguid”
group by t.id
having count(t.id)>1
) as num
from rats.ttsbs01 st
所以我还是怀疑可能跟嵌套太多有关。
展开