EXPLAIN SELECT S.ITEMID, X.STATUS
FROM
(select itemid,itemdescription from A WHERE parent_itemid IN(SELECT ITEMID FROM A WHERE itemtype='CT') AND itemtype='SK' AND id='02') S,
(select s1.itemid from s1,s2 where s1.itemid=s2.itemid and status='RC' ) X
where S.itemid=X.itemid
引起问题的不是相关子查询,而是语法。不仅explain
,而且explain plan for
。
我没有你的桌子,所以我用了斯科特的(正确加入):
SQL> explain plan for select s.dname, x.ename
2 from (select d.deptno,
3 d.dname
4 from dept d
5 where d.deptno in (select b.deptno
6 from dept b
7 where b.deptno = 10
8 )
9 ) s join
10 (select e.deptno,
11 e.ename
12 from emp e
13 where e.deptno = 10
14 ) x
15 on s.deptno = x.deptno;
Explained.
SQL>
在你的情况下,假设其他一切都是正确的,
explain plan for select s.itemid, x.status
from (select a.itemid,
a.itemdescription
from a
where a.parent_itemid in (select b.itemid
from a b
where b.itemtype = 'CT'
)
and a.itemtype = 'SK'
and a.id = '02'
) s join
(select s1.itemid
from s1 join s2 on s1.itemid = s2.itemid
where s1.status = 'RC' --> which table does STATUS belong to?
) x
on s.itemid = x.itemid;
我还建议您始终使用表别名,因为不清楚什么属于哪个表。例如,status = 'RC'
- 没有别名,就不可能知道哪个表有它。如果两者都有,你就会有歧义。
最后,编写格式化查询。您发布的混乱难以阅读和理解。大多数现代 GUI 工具都有内置的格式化程序;我建议你使用它。或者,使用在线格式化程序之一。或者,手动格式化。尽量不要做你现在正在做的事情。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句