SELECT
     t.aoi_name,
     ( SELECT count(p.per_id) FROM d_person_info p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.input_date > to_date('2010-10-10','yyyy-mm-dd') and p.input_date < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_person,
     ( SELECT count(p.per_id) FROM d_body_check_info p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.BCI_DATE > to_date('2010-10-10','yyyy-mm-dd') and p.BCI_DATE < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_bodycheck,
     ( SELECT count(p.per_id) FROM D_NEWBORN_HOME_VISIT p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.new_visitDate > to_date('2010-10-10','yyyy-mm-dd') and p.new_visitDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_born,
     ( SELECT count(p.per_id) FROM D_oneChild_health_exam p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.OC_visitDate > to_date('2010-10-10','yyyy-mm-dd') and p.OC_visitDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_one,
     ( SELECT count(p.per_id) FROM D_twoChild_health_exam p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.TWC_visitDate > to_date('2010-10-10','yyyy-mm-dd') and p.TWC_visitDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_two,
     ( SELECT count(p.per_id) FROM D_CHILD_HEALTH_EXAM p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.CHE_DATE > to_date('2010-10-10','yyyy-mm-dd') and p.CHE_DATE < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_six,
     ( SELECT count(p.per_id) FROM D_FIRST_follow_service p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.ffs_fillDate > to_date('2010-10-10','yyyy-mm-dd') and p.ffs_fillDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_first,
     ( SELECT count(p.per_id) FROM D_follow_service_info p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.fts_wVisDate > to_date('2010-10-10','yyyy-mm-dd') and p.fts_wVisDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_second,
     ( SELECT count(p.per_id) FROM D_Postpartum_visits p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.pv_followDate > to_date('2010-10-10','yyyy-mm-dd') and p.pv_followDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_postpartum,
     ( SELECT count(p.per_id) FROM D_Postpartum_healthCheck p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.phc_followDate > to_date('2010-10-10','yyyy-mm-dd') and p.phc_followDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_postpartum_health,
     ( SELECT count(p.per_id) FROM D_DPF_Record_INFO p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.DPF_Date > to_date('2010-10-10','yyyy-mm-dd') and p.DPF_Date < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_dpf,
     ( SELECT count(p.per_id) FROM D_HPFS_RECORD_INFO p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.HPF_DATE > to_date('2010-10-10','yyyy-mm-dd') and p.HPF_DATE < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_hpfs,
     ( SELECT count(p.per_id) FROM D_GMIP_Follow_INFO p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.GMF_FollowDate > to_date('2010-10-10','yyyy-mm-dd') and p.GMF_FollowDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_gmf,
     ( SELECT count(p.per_id) FROM D_Infectious_DIS p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.DID_DDate > to_date('2010-10-10','yyyy-mm-dd') and p.DID_DDate < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_infectious,
     ( SELECT count(p.per_id) FROM D_Older_Case_Info p, m_user_info u WHERE u.aoi_id = t.aoi_id and u.user_id = p.input_user and p.valid = '1' and p.OLDC_follow_Date > to_date('2010-10-10','yyyy-mm-dd') and p.OLDC_follow_Date < to_date('2012-10-10','yyyy-mm-dd')+1 ) v_older
  FROM m_admin_organ_info t , s_organ_info b
 WHERE t.org_id = b.org_id
   and t.valid = '1' and t.area_sid like '36012210%' and b.ole_id='2'
针对你的查询条件 来建立所以
一般where
里面包含的 条件建立个索引
会快一点条件这里这么建立索引,啊。真心不这么会。sql

解决方案 »

  1.   


    和表多少没关系。
    你的各种P表, 我觉得可以先和m_admin_organ_info t , s_organ_info b 关联过滤出最小集合。只是建议。
      

  2.   

    可以考虑改变一下业务逻辑;
    查询里面的那一堆count(xx) 可以考虑弄个临时表;
    建索引的话,哪些字段常用,且有较大的识别度,能过滤掉大部分数据,就在该字段建;
     起码这个需要建一下:t.org_id = b.org_id 
      

  3.   

    试试加并行吧,  不建议楼主一个sql这样写。反而降低磁盘io,性能更慢。
      

  4.   


    select * from (select ) 吗。