CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  基础类

各位高人请留步,不看白不看哈!:)))(()))

楼主liuex1235(盲流)2006-03-04 14:16:50 在 MS-SQL Server / 基础类 提问

table1  
  product_no     product_id     prod_addr  
   
  table2  
  product_id       obj_id  
   
  table3  
  connect_id     connect_code  
   
  table4  
  phone_no     cust_id  
   
  table5  
  cust_id       cust_name  
   
  条件  
  where   table1.product_id=table2.product_id  
  table2.obj_id=table3.connect_id  
  table4.cust_id=table5.cust_id  
  table4.phone_no=table1.product.no  
   
  结果  
  table1.prod_addr           table1.product_no         cust_name           table3.connect_code  
  _________________       __________________       ___________       ____________________  
   
  我写的语句如下:  
   
  select   a.prod_addr,a.product_no,c.connect_code,e.cust_name  
  where  
          a.product_id=b.product_id  
  and   b.obj_id=c.connect_id    
  and   d.cust_id=e.cust_id  
  and   d.phone_no=a.product_no  
  from   table1   a,table2   b,table3   c,table4   d,   table5   e      
   
  得到结果出现N条重复的记录  
  请问我写的这个查询问题在哪?  
  象是出现笛卡儿乘积现象。  
  如何改?谢谢了!  
  急等!            
   
  问题点数:100、回复次数:7Top

1 楼Codavid()回复于 2006-03-04 14:23:07 得分 5

一次得不到吧!我想是用几次子查询Top

2 楼wgsasd311(自强不息)回复于 2006-03-04 14:36:59 得分 5

--try  
  select   distinct   a.prod_addr,a.product_no,c.connect_code,e.cust_name  
  from   table1   a,table2   b,table3   c,table4   d,   table5   e    
  where  
  a.product_id=b.product_id  
  and   b.obj_id=c.connect_id    
  and   a.product_no=d.phone_no  
  and   d.cust_id=e.cust_idTop

3 楼liuex1235(盲流)回复于 2006-03-04 14:45:33 得分 0

这个查询用于建视图所用,distinct最后虽然可以得到最后结果,但是耗费的时间实在太长。  
  1条记录就重复了几十万遍。实在无法想象!  
  谢谢各位,继续顶!Top

4 楼liuex1235(盲流)回复于 2006-03-04 14:47:49 得分 0

不好意思,纠正一下,from写到后面来了!  
  我写的语句是这样的!  
  select   distinct   a.prod_addr,a.product_no,c.connect_code,e.cust_name  
  from   table1   a,table2   b,table3   c,table4   d,   table5   e    
  where  
  a.product_id=b.product_id  
  and   b.obj_id=c.connect_id    
  and   a.product_no=d.phone_no  
  and   d.cust_id=e.cust_id  
   
  Top

5 楼wgsasd311(自强不息)回复于 2006-03-04 15:17:52 得分 90

--try  
  select   distinct   a.prod_addr,a.product_no,  
  b.connect_code,  
  c.cust_name  
  from   table1   a,  
  (select   distinct   a.product_id,b.connect_code   from   table2   a   inner   join   table3   b   on     a.obj_id=b.connect_id   )   b,  
  (select   distinct   a.phone_no,b.cust_name   from   table4   a   inner   join   table5   b   on     a.cust_id=b.cust_id   )   c  
  where  
  a.product_id=b.product_id    
  and   a.product_no=c.phone_no  
   
  Top

6 楼liuex1235(盲流)回复于 2006-03-04 16:01:15 得分 0

ok,我试下看,成功后马上结帖!谢谢Top

7 楼Codavid()回复于 2006-03-04 22:03:45 得分 0

我也是这样想的,但太复杂了,没写出来!哈哈!  
   
  可心问一下,inner   join和join   有什么区别吗?Top

相关问题

  • >>>> 各位,请留步进来摸个彩……
  • 一个小问题,请各位留步!(关于gif的)
  • 各位师兄师姐请留步,帮小弟一个忙
  • 高手请留步!
  • 斑竹请留步!
  • 高手,请留步
  • 各位请留步!一个很急的问题不看绝对后悔....
  • 各位大哥请留步 帮小弟看看这个超简单的问题!
  • 各位高手请留步,向你们打探一下行业的情况
  • 公司想招一个技术部经理,各位牛人请留步看看

关键词

  • code
  • cust
  • idtable
  • idand
  • prod
  • product
  • namefrom
  • distinct
  • phone
  • table

得分解答快速导航

  • 帖主:liuex1235
  • Codavid
  • wgsasd311
  • wgsasd311

相关链接

  • SQL Server类图书

广告也精彩

反馈

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