select a.*,
(select max(decode(wjsymc, 'DW', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) DW,
(select max(decode(wjsymc, 'ND', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) ND,
(select max(decode(wjsymc, 'KTXM', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) KTXM,
(select max(decode(wjsymc, 'GQ', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) GQ,
(select max(decode(wjsymc, 'SJCXS', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) SJCXS,
(select max(decode(wjsymc, 'SJDW', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) SJDW,
(select max(decode(wjsymc, 'BXR', wjsyz, null)) from epdm_bgwd_sy b where a.ttachment_journal_id=b.ttachment_journal_id) BXR
from CD_ATTACHMENT_JOURNAL a where a.flid='003'如上sql,CD_ATTACHMENT_JOURNAL表中搜索出的信息要和epdm_bgwd_sy表搜索出行转列的数据合起来,有更好的方法吗?epdm_bgwd_sy表中有外键ttachment_journal_id,对应CD_ATTACHMENT_JOURNAL表中的主键。

解决方案 »

  1.   


    select a.*, b.dw, b.nd, b.ktxm, b.gq, b.sjcxs, b.sjdw, b.bxr
      from CD_ATTACHMENT_JOURNAL a,
           (select ttachment_journal_id,
                   max(decode(wjsymc, 'DW', wjsyz, null)) DW,
                   max(decode(wjsymc, 'ND', wjsyz, null)) ND,
                   max(decode(wjsymc, 'KTXM', wjsyz, null)) KTXM,
                   max(decode(wjsymc, 'GQ', wjsyz, null)) GQ,
                   max(decode(wjsymc, 'SJCXS', wjsyz, null)) SJCXS,
                   max(decode(wjsymc, 'SJDW', wjsyz, null)) SJDW,
                   max(decode(wjsymc, 'BXR', wjsyz, null)) BXR
              from epdm_bgwd_sy
             group by ttachment_journal_id) b
     where a.ttachment_journal_id = b.ttachment_journal_id(+)
       and a.flid = '003'
    试试看行不行