select collection_id,character1 ,character3 ,'' as s ,'' as T,'' as 缺點
from Qa_Results 
where  character1 = 'A' and collection_id in
             ( select collection_id from Qa_Results where RECEIPT_NUM = '304110034')
order by collection_id,receipt_num
union
select C.collection_id,C.character1 ,C.character3 ,'s' as s ,D.character1  as T,D.CHARACTER3 as 缺點
from Qa_Results C,Qa_Results D
where  C.collection_id = D.collection_id and 
       length(D.CHARACTER1) > 1 and
       C.character1 = 'R' and C.collection_id in
             ( select collection_id from Qa_Results where RECEIPT_NUM = '304110034')
order by C.collection_id,C.receipt_num

解决方案 »

  1.   

    select a.collection_id,a.character1,a.character3,b.s,c.t,c.缺點 from (select collection_id,CHARACTER1,CHARACTER3 from Qa_Results where RECEIPT_NUM = '304110034' and CHARACTER3 in ('拒絕','接受') a,select COLLECTION_ID,CHARACTER1 s from Qa_Results where RECEIPT_NUM = '304110034' and (CHARACTER3='' or CHARACTER3 is null)) b,(select COLLECTION_ID, CHARACTER1 t, CHARACTER3 缺點 from Qa_Results where RECEIPT_NUM = '304110034' and CHARACTER3 like '%缺點%') c where a.collection_id=b.collection_id(+) and a.collection_id=c.collection_id(+);
      

  2.   

    很感謝 qiaozhiwei(乔)的回答:我再想問一個為什麼會多產生兩個空行呢?我加了distinct的結果也一樣?
    COLLECTION_ID CHARACTER1 CHARACTER3 S T 缺點
    65869                   R 拒絕          s TBD-04 主缺點
    65872                   R 拒絕          s TFO-99 次缺點
    65877                   A
    65877                   R 拒絕          s VPS-17 主缺點
    65886                   A 接受
    65889                   A 接受
    65896                   A
    65896                   R 拒絕          s VPS-02 次缺點
    65899                   R 拒絕          s TBD-01 主缺點
    65902                   R 拒絕          s TBD-02 主缺點
      

  3.   

    可能是你的表里有冲突数据,比如:COLLECTION_ID 为 65877的记录有两中情况一种是接受,另一种是拒绝,这是不应该的吧,你检查一下原始数据
      

  4.   

    to: qiaozhiwei(乔)
    多產生空行已經解決select collection_id,character1 ,character3 ,'' as s ,'' as T,'' as 缺點
    from Qa_Results 
    where  character1 = 'A' and collection_id in
                 ( select collection_id from Qa_Results where RECEIPT_NUM = '304110034')
    union
    select C.collection_id,C.character1 ,C.character3 ,'s' as s ,D.character1  as --!!!!!!!!T,D.CHARACTER3 as 缺點
    from Qa_Results C,Qa_Results D
    where  C.collection_id = D.collection_id and 
           length(D.CHARACTER1) > 1 and
           C.character1 = 'R' and C.collection_id in
                 ( select collection_id from Qa_Results where RECEIPT_NUM = '304110034')上面's' as s ,D.character1  as --!!!!!!!!中's' as s 但我數據庫中不僅有值s還有A和I兩個值
    怎麼從數據庫中提出來呢?
    謝謝
      

  5.   

    字段是不是没给全,不太好写,自己再改改select Q1.collection_id,Q1.character1 ,Q1.character3 ,Q2.character1,Q3.character1,Q3.character3  from Qa_Results Q1,Qa_Results Q2,Qa_Results Q3 where  Q1.RECEIPT_NUM = '304110034' and Q1.character1 in('A','R') and Q2.character1 in('S') and Q3.character1 like '%-%' and Q1.collection_id = Q2.collection_id(+) and Q1.collection_id = Q3.collection_id(+)
      

  6.   

    恩,ORARichard(没钱的日子好难过啊) 水平不错,应该不会很穷吧。