CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Oracle >  开发

如何优化这一查询!!!

楼主zero2learn(zero2learn)2006-05-01 23:44:26 在 Oracle / 开发 提问

有如下两张表 表结构如下:(数据量都比较大 都当有1千万把)  
  tab1  
  -------------------------------------------------  
  id           card             name           type             intime    
  1             1001             jacke         a100             20050401  
  2             1001             jackie       a100             20050401  
  3             1002             anti           a200             20050401  
  4             1002             anti           a200             20050401  
  5             1003             wack           a300             20050401  
  6             1004             waee           a400             20050402  
  7   00                 tt             a500             20050401  
  8               00                 tt             a500             20050401  
  ..           ..                 ..               ..             ........  
  --------------------------------------------  
  tab2  
  --------------------------------------------------  
  type         typename         other1       other2  
  a100           import             test1         test2  
  a200           import             test3         test4  
  a300           noimport         test5         test6  
  a400           noimport         test7         test8  
  a500           import             test9         test10  
  ..               ..                     ..               ...  
  --------------------------------  
   
  现在要做如下查询 在Tab1   中card   出现次数大于1的记录并且时间字段(intime)为指定一具体值(比如20060501),需要显示 card   ,name   ,type   ,intime,typename,   other1,other2   这些字段 两张表的关联是 type   这一字段 card 的长度小于4位 不予理睬 不做显示!由于数据两表数据比较大 我做的查询速度慢!我只这么做的  
   先建立一张试图(view1)  
   select   card   ,name   ,type   intime,typename   from   tabl   where   card   in(select   card   from   tab1   where   intime='20050401'   group   by   card   having   count(card)>1)   and   intime='20050401'  
    然后 view1 有   tab2 在做关联(我做的暂不考虑card的长度)   因为速度太慢 希望大家给我一点建议!!不甚感激!!!  
  按照要求查询结果应该如下:  
  1001             jacke         a100             20050401 import             test1         test2  
  1001             jacke         a100             20050401 import             test3         test4  
  1002             anti           a200             20050401 noimport         test5         test6  
  1002             anti           a200             20050401 noimport         test7         test8  
  ============================================================================  
  问题点数:20、回复次数:1Top

1 楼xiaoxi_LION(小溪 世界上只有一种东西不会因为你的付出太多而变少,那就是--爱!!!!)回复于 2006-05-05 17:15:34 得分 20

我个人的一点建议:  
  1.保证tab1上的type,intime,tab2   的type   上均建有索引,且确保你的查询的执行计划先按intime进行索引,这样在你按intime查询时,速度应该会有很大的提升;  
  2.可以把in查询改为:   exists  
  Top

相关问题

关键词

得分解答快速导航

  • 帖主:zero2learn
  • xiaoxi_LION

相关链接

  • Oracle类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo