张志峰的博客

水滴石川,积少成多。

导航

Sql 一个SQL语句的优化

Posted on 2011-12-07 14:10  ╰★张志峰★╮  阅读(229)  评论(0编辑  收藏  举报

这是一个sql语句优化的过程。使用子查询与不使用子查询的效率对比

select sum(sl0000) from xstfxps2 where
  dhao00 in (
  select dhao00 from xstfxps1 where trunc(ywrq00)=trunc(sysdate)
  and khdm00='500000003913');
已用时间: 00: 02: 49.04

select sum(sl0000)
  from xstfxps2 a,(select dhao00 from xstfxps1 where trunc(ywrq00)=trunc(sysdate)
  and khdm00='500000003913') b
  where a.dhao00=b.dhao00;
已用时间: 00: 00: 03.05