select * from t_resource_cell where res_id in ( select c.res_id from t_resource_cell c  inner join t_resource_type t on c.res_id = t.res_id  where c.status != 'D'  and c.mtype_id in (select mtype_id from d_resource_mtype where parent_id in ('RT') or mtype_id in ('RT') )    and ( (c.tmcp_id is not null and c.tmcp_id in ('BQ0007')) or (c.tmcp_id is null and c.res_id in ( select res_id from t_resource_tmcp where tmcp_id in ('BQ0007') ) ) )      and t.type1_id = '2100' and t.type2_id = '8100'    ) 请帮忙看看怎么能将这个查询优化一下!

解决方案 »

  1.   

    in 操作看看是否可以替换成其他的,比如exists
      

  2.   

    select * from t_resource_cell c
        where c.status != 'D'
          and c.mtype_id in (select mtype_id from d_resource_mtype where parent_id in ('RT') or mtype_id in ('RT') )
          and (   (c.tmcp_id is not null and c.tmcp_id in ('BQ0007') )
               or (c.tmcp_id is null and c.res_id in ( select res_id from t_resource_tmcp where tmcp_id in ('BQ0007') ) ) )
          and exists (select 1 from t_resource_type t
                          where c.res_id = t.res_id
                            and t.type1_id = '2100' and t.type2_id = '8100')