select * from wms_depot T where T.DEPOTID IN 
(select T.DEPOTID from wms_depot T where T.DEPOTID 
IN (select T.DEPOTID from wms_depot T where T.DEPOTID = 10002 OR T.DEPOTPARENTID = 10002)
OR T.DEPOTPARENTID IN (select T.DEPOTID from wms_depot T where T.DEPOTID = 10002 OR T.DEPOTPARENTID = 10002))
OR T.DEPOTPARENTID IN (select T.DEPOTID from wms_depot T where T.DEPOTID 
IN (select T.DEPOTID from wms_depot T where T.DEPOTID = 10002 OR T.DEPOTPARENTID = 10002)
OR T.DEPOTPARENTID IN (select T.DEPOTID from wms_depot T where T.DEPOTID = 10002 OR T.DEPOTPARENTID = 10002))

解决方案 »

  1.   

    可以使用ORACLE中的集合函数进行优化。
      

  2.   

    1)通过把in换为exists,看看执行计划有无改善
    2)用with子句,把in的部分先灌进临时表,再来select,如果数据量不大的话
      

  3.   

    看了半天才看明白,根据一个部门id求出它的下面所有的部门,嵌套这么层干嘛啊,汗。。
    看看下面的写法是否满足你的需求:SELECT t.*
      FROM wms_depot t
     START WITH t.DEPOTID = 10002
    CONNECT BY PRIOR t.DEPOTID = t.DEPOTPARENTID