ting-gpng 发表于 2015-9-24 10:53:36

求帮忙优化一下SQL

SELECT ltrim(rtrim(ta_main8.c_dpt_cde)),COALESCE(CHAR(TA_MAINC.N_CLM_COUNT),'0'),
0,0,
sum(1),
sum(ta_main8.n_prm_var_yuan),
0, 0, 0, 0,0, 0, 'A'
FROM rpt_plyedr TA_MAIN8 LEFT OUTER JOIN (SELECT C_PLY_NO,COUNT(DISTINCT c_clm_no) N_CLM_COUNT FROM RPT_CLM_MAIN WHERE C_CNL_MRK = 'Z' GROUP BY C_PLY_NO) TA_MAINC ON TA_MAINC.C_PLY_NO =TA_MAIN8.C_PLY_NO
WHERE TA_MAIN8.t_insrnc_end_tmBETWEEN   '2015-09-23-00.00.00.000000'AND'2015-09-23-23.59.59.999999'
      and ta_main8.c_edr_type = '0'
      and (ta_main8.c_ply_status not in ('2','3')
         or (ta_main8.c_ply_statusin ('2','3') and ta_main8.t_end_tm > '2015-09-23-23.59.59.999999'))
      and ta_main8.c_kind_no not in ( '03')
AND TA_MAIN8.C_PROD_NO BETWEEN '0101' AND '2650'AND TA_MAIN8.GN_INTER_CDE LIKE '99%'
GROUP BY ltrim(rtrim(ta_main8.c_dpt_cde)),COALESCE(CHAR(TA_MAINC.N_CLM_COUNT),'0');

求助:怎么改写,避免对(SELECT C_PLY_NO,COUNT(DISTINCT c_clm_no) N_CLM_COUNT FROM RPT_CLM_MAIN WHERE C_CNL_MRK = 'Z' GROUP BY C_PLY_NO)的全表扫描排序??
页: [1]
查看完整版本: 求帮忙优化一下SQL