下面这条语句怎么优化?
select ch,jxlb,jdrq,a.cjdw from t_jxfy_dx a
where  ch||jdrq in (select ch||max(jdrq) from t_jxfy_dx f where jxlb='段修' and sdrq <= sysdate group by ch)

解决方案 »

  1.   

    select ch,jxlb,jdrq,a.cjdw from t_jxfy_dx a a1
    inner join
    (select ch||max(jdrq) temp from t_jxfy_dx f where jxlb='段修' and sdrq <= sysdate group by ch)t
    on t.temp = a1.ch||a1.jdrq
      

  2.   

    hongqi162: 我用优化工具测试了,速度没大的改观。这条语句能用exists 改吗?
      

  3.   

    select ch,jxlb,jdrq,a.cjdw from t_jxfy_dx a
    where ch||jdrq exists (select ch||max(jdrq) from t_jxfy_dx f where jxlb='段修' and sdrq <= sysdate group by ch)
    用exists应该和in差不多
      

  4.   

    直接这样写,会怎么样呢?
    select ch,jxlb,max(jdrq),cjdw  from t_jxfy_dx
    where jxlb='段修' and sdrq <= sysdate
    group by ch,jxlb,cjdw
      

  5.   

    select ch,jxlb,jdrq,a.cjdw from t_jxfy_dx a
    where  exists 
    (select 0 from (select ch,max(jdrq) jdrq from t_jxfy_dx f where jxlb='段修' and sdrq <= sysdate group by ch) c
    where c.cb=a.cb and c.jdrq=a.jdrq
      

  6.   

    主键 是ch,jxlb,jdrq 谢谢各位了,还有最优化的语句没,贴出的语句只是一部,是一个大的sql 现在运行起来太慢了,想修改下。