CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Oracle >  开发

在一個表中重復查詢中一個fields對應多個value的問題 已解決一部分,請大家幫再看看!!!謝謝

楼主dy18(黎明之目)2004-12-02 20:39:54 在 Oracle / 开发 提问

原貼:  
  http://community.csdn.net/Expert/topic/3608/3608660.xml?temp=.1835749  
  很感謝大家的幫忙,基本得到部分想得到的數據,尤其感謝ORARichard(没钱的日子好难过啊)  
   
  SQL>select   collection_id,character1   ,character3   from   Qa_Results   where     collection_id   in  
  (   select   collection_id   from   Qa_Results   where   RECEIPT_NUM   =   '304110034')  
  order   by   collection_id,receipt_num  
   
   
  COLLECTION_ID CHARACTER1 CHARACTER3  
   
  65869                                 R                   拒絕  
  65869                                 S  
  65869                                 TBD-04 主缺點  
  65872                                 R                   拒絕  
  65872                                 S  
  65872                                 TFO-99 次缺點  
  65886                                 A                   接受  
  65889                                 A                   接受  
   
   
  我想通過一個select語句得一下如下的結果:(新增三個fields:s、T、缺點)  
   
  COLLECTION_ID   CHARACTER1     CHARACTER3     s     T               缺點  
   
  65869                         R           拒絕                 s     TBD-04   主缺點  
  65872                         R           拒絕                 s     TFO-99   次缺點  
  65886                         A           接受  
  65889                         A           接受  
  請問怎麼做呢?(S   列中的值不是固定的如果為接受s,t,缺點都為空)  
  下面的解法:fields  S 的值能夠從數據庫提出來,但fields“T、缺點”的值得不到(查詢結果為空)  
  select   Q1.collection_id,Q1.character1   ,Q1.character3   ,Q2.character1,Q3.character1,Q3.character3    
  from   (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3='拒絕'   and   RECEIPT_NUM   =   '304110034')   q1,  
  (select   collection_id,character1   from   qa_results   where   CHARACTER3   is   null   or   CHARACTER3=''   and   RECEIPT_NUM   =   '304110034')   q2,  
  (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3   not   in   ('拒絕','接受','',null   and   RECEIPT_NUM   =   '304110034')   q3  
  where   q1.collection_id=q2.collection_id(+)   and   q1.collection_id=q3.collection_id(+)  
  问题点数:100、回复次数:7Top

1 楼dy18(黎明之目)回复于 2004-12-02 20:46:07 得分 0

也就是:Q3.character1,Q3.character3   的值代不出來!!!  
  請大家幫看一下!  
  謝謝  
  Top

2 楼ORARichard(没钱的日子......)回复于 2004-12-02 21:12:09 得分 100

对不起,原贴中没注意写错一个地方  
   
  --try:  
   
  select   Q1.collection_id,Q1.character1   ,Q1.character3   ,Q2.character1,Q3.character1,Q3.character3    
  from   (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3='拒絕'   and   RECEIPT_NUM   =   '304110034')   q1,  
  (select   collection_id,character1   from   qa_results   where   (CHARACTER3   is   null   or   CHARACTER3='')   and   RECEIPT_NUM   =   '304110034')   q2,  
  (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3   not   in   ('拒絕','接受','',null   and   RECEIPT_NUM   =   '304110034')   q3  
  where   q1.collection_id=q2.collection_id(+)   and   q1.collection_id=q3.collection_id(+)  
   
  Top

3 楼ORARichard(没钱的日子......)回复于 2004-12-02 21:13:45 得分 0

(select   collection_id,character1   from   qa_results   where   (CHARACTER3   is   null   or   CHARACTER3='')   and   RECEIPT_NUM   =   '304110034')   q2,  
  这个结果集中条件应该是  
  where   (...   or   ...)   and   ...  
   
  而原来那句写成了   where   ...   or   ...   and   ...Top

4 楼dy18(黎明之目)回复于 2004-12-02 21:47:23 得分 0

select   Q1.collection_id,Q1.character1   ,Q1.character3   ,Q2.character1,Q3.character1,Q3.character3    
  from   (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3='拒絕'   and   RECEIPT_NUM   =   '304110034')   q1,  
  (select   collection_id,character1   from   qa_results   where   (CHARACTER3   is   null   or   CHARACTER3='')   and   RECEIPT_NUM   =   '304110034')   q2,  
  (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3   not   in   ('拒絕','接受','',null)   and   RECEIPT_NUM   =   '304110034')   q3  
  where   q1.collection_id=q2.collection_id(+)   and   q1.collection_id=q3.collection_id(+)  
   
  這樣後一Q2.character1,Q3.character1,Q3.character3   的值都沒有了???Top

5 楼ORARichard(没钱的日子......)回复于 2004-12-02 21:57:23 得分 0

你把三个结果集分别单独做一下,看看都能取到什么样的结果集,然后把结果贴出来Top

6 楼ORARichard(没钱的日子......)回复于 2004-12-02 22:34:17 得分 0

select   Q1.collection_id,Q1.character1   ,Q1.character3   ,Q2.character1,Q3.character1,Q3.character3  
  from   (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3='拒絕'   and   RECEIPT_NUM   =   '304110034')   q1,  
  (select   collection_id,character1   from   qa_results   where   (CHARACTER3   is   null   or   CHARACTER3='')   and   RECEIPT_NUM   =   '304110034')   q2,  
  (select   collection_id,character1   ,character3   from   qa_results   where   (character3   !='拒絕'   and   length(character3)>0   and   character3   !='接受')   and   RECEIPT_NUM   =   '304110034')   q3  
  where   q1.collection_id=q2.collection_id(+)   and   q1.collection_id=q3.collection_id(+)    
  union   select   collection_id,character1   ,character3,null,null,null   from   qa_results   where   CHARACTER3='接受';Top

7 楼ORARichard(没钱的日子......)回复于 2004-12-02 22:36:35 得分 0

--retry:  
   
  select   Q1.collection_id,Q1.character1   ,Q1.character3   ,Q2.character1,Q3.character1,Q3.character3  
  from   (select   collection_id,character1   ,character3   from   qa_results   where   CHARACTER3='拒絕'   and   RECEIPT_NUM   =   '304110034')   q1,  
  (select   collection_id,character1   from   qa_results   where   (CHARACTER3   is   null   or   CHARACTER3='')   and   RECEIPT_NUM   =   '304110034')   q2,  
  (select   collection_id,character1   ,character3   from   qa_results   where   (character3   !='拒絕'   and   length(character3)>0   and   character3   !='接受')   and   RECEIPT_NUM   =   '304110034')   q3  
  where   q1.collection_id=q2.collection_id(+)   and   q1.collection_id=q3.collection_id(+)    
  union   select   collection_id,character1   ,character3,null,null,null   from   qa_results   where   CHARACTER3='接受'   and   RECEIPT_NUM   =   '304110034';Top

相关问题

  • fields不理解
  • cloneNode丢失value求解
  • checkbox子表单上的中文value传到主表单上是某种加密的代码,怎样才能解决,急
  • jsp中,表单中的checkbox的状态如何取得,request.getParameter得到的是value?大家是如何解决这个问题的??
  • 数据库更新级联菜单的问题,怎么样从下拉列表获得的value或者text中取数据进行查询?(解决就送分)
  • CheckBox的Value值如何表示??
  • 如何理解链表?
  • 注册表怎样解锁?
  • 如何解琐注册表?
  • 什么是解析表?

关键词

  • null
  • character
  • receipt
  • collection
  • 拒絕
  • 缺點
  • 接受
  • results where
  • num
  • from qa

得分解答快速导航

  • 帖主:dy18
  • ORARichard

相关链接

  • Oracle类图书

广告也精彩

反馈

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