日期:2014-05-16 浏览次数:21149 次
select distinct * from (select /*+ leading(T_CARDINFO) INDEX(T_CARDINFO CI_XM_INDEX) INDEX(T_CARDTIME T_CHECKTIME_INDEX) */ T_CARDINFO.*, rownum rn from T_CARDINFO, T_CARDTIME where CI_SFZH = CT_SFZH and exists (select 'x' from T_CARDTIME where CI_SFZH = CT_SFZH and CT_YZSJ >= to_date('20010501', 'YYYYMMDD') and CT_YZSJ <= to_date('20110921', 'YYYYMMDD')) and CI_XM = '李明' and CT_CHECK_USER like '800300020600%' and rownum < 21) t WHERE t.rn >= 1
SELECT /*+ leading(T_CARDINFO) INDEX(T_CARDINFO CI_XM_INDEX) INDEX(T_CARDTIME T_CHECKTIME_INDEX) */ DISTINCT T_CARDINFO.* FROM T_CARDINFO WHERE EXISTS (SELECT 'x' FROM T_CARDTIME WHERE CI_SFZH = CT_SFZH AND CT_YZSJ >= TO_DATE('20010501', 'YYYYMMDD') AND CT_YZSJ <= TO_DATE('20110921', 'YYYYMMDD') AND CT_CHECK_USER LIKE '800300020600%') AND CI_XM = '李明' AND ROWNUM < 21 ;
------解决方案--------------------
语句套的层太多。完全减少层数。可以不用distinct,把表的别名带到字段中去。