ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 关于活用Distinct in Sql Statement 中

关于活用Distinct in Sql Statement 中

原创 Linux操作系统 作者:Kenniu 时间:2019-05-22 21:57:05 0 删除 编辑

我遇到的问题也许其它人也会遇到,特分享我的经验给大家;其内容如标题所谈;

我有四个Table 做Join; 其中有一个Table 数据较大4,671,110,且每天以10K多的数据在增加;

一开始,我写了如下Sql Statement:

select a.invn, b.cbar, d.dsca, a.ship_date
from T01 a,T02 b,T03 c,(select distinct ccty,dsca from T04 ) d

where b.pino=a.pino and c.pino=a.pino and c.ccty=d.ccty and a.ncmp =b.ncmp and b.ncmp=c.ncmp and a.invn='XXXX'

执行的结果: 4.67 seconds

这样的结果绝对不是我想要的;

我试了如下语句:

select a.invn, b.cbar, d.dsca, a.ship_date
from T01 a,T02 b,T03 c,(select ccty,dsca from T04 ) d

where b.pino=a.pino and c.pino=a.pino and c.ccty=d.ccty and a.ncmp =b.ncmp and b.ncmp=c.ncmp and a.invn='XXXX'

执行的结果: 0.01 second

在Table T04中,有重复的记录;如果对整个执行结果再进行Distinct; 它的执行效果会更好呢.我试了如下语句:

select distinct a.invn, b.cbar, d.dsca, a.ship_date
from T01 a,T02 b,T03 c,(select ccty,dsca from T04 ) d

where b.pino=a.pino and c.pino=a.pino and c.ccty=d.ccty and a.ncmp =b.ncmp and b.ncmp=c.ncmp and a.invn='XXXX'

执行的结果: 0.23 seconds

这个结果我可以接受;

这样的做法会在其它DB做DB Link 访问时,他的执行效率会大大地改善;


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30193/viewspace-89987/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2002-11-29

  • 博文量
    146
  • 访问量
    122502