コメントのようにデータについて、特に代替name値を照合して選択する方法について、いくつかの仮定を立てます。そして、私があなたのものと一致すると思ういくつかのダミーデータで:
create table tablea(out_num number,
    equip_name varchar2(5),
    event_type varchar2(10),
    comments varchar2(10),
    timestamp date, feed_id number);
create table tableb(id number, name varchar2(10));
alter session set nls_date_format = 'MM/DD/YYYY HH24:MI';
insert into tablea values (12345, null, 'abcd', null, to_date('02/11/2013 11:12'), 1);
insert into tablea values (12345, null, 'abcd', null, to_date('02/11/2013 11:11'), 1);
insert into tablea values (12345, null, 'abcd', null, to_date('02/11/2013 11:06'), 1);
insert into tablea values (12345, null, 'abcd', null, to_date('02/11/2013 11:06'), 1);
insert into tablea values (12345, null, 'SUB', null, to_date('02/11/2013 11:11'), 2);
insert into tablea values (12345, null, 'SUB', null, to_date('02/11/2013 11:12'), 2);
insert into tablea values (12345, null, 'XYZ', null, to_date('02/11/2013 11:13'), 3);
insert into tablea values (12345, null, 'XYZ', null, to_date('02/11/2013 11:13'), 3);
insert into tablea values (12345, null, 'XYZ', null, to_date('02/11/2013 11:13'), 3);
insert into tablea values (12345, null, 'XYZ', null, to_date('02/11/2013 11:13'), 3);
insert into tablea values (12345, null, 'XYZ', null, to_date('02/11/2013 11:13'), 3);
insert into tablea values (12345, null, 'XYZ', null, to_date('02/11/2013 11:03'), 3);
insert into tablea values (12345, null, 'CAUSE', 'APPLE', to_date('02/11/2013 11:13'), 4);
insert into tablea values (12345, null, 'CAUSE', 'APPLE', to_date('02/11/2013 11:13'), 4);
insert into tablea values (12345, null, 'CAUSE', 'APPLE', to_date('02/11/2013 11:13'), 4);
insert into tablea values (12345, null, 'STATUS', 'BOOKS', to_date('02/11/2013 11:13'), 5);
insert into tablea values (12345, null, 'STATUS', 'BOOKS', to_date('02/11/2013 11:13'), 5);
insert into tablea values (12345, null, 'STATUS', 'BOOKS', to_date('02/11/2013 11:03'), 5);
insert into tableb values(3, 'LION');
これで結果が得られます。
select * from (
    select a.out_num,
        a.timestamp,
        a.equip_name,
        a.event_type,
        a.comments,
        coalesce(b.name,
            first_value(b.name)
                over (partition by a.out_num
                    order by b.name nulls last)) as name
    from tablea a
    left outer join tableb b on a.feed_id = b.id
    where a.out_num = '12345'
    and a.event_type in ('CAUSE', 'STATUS', 'XYZ')
)
where event_type in ('CAUSE', 'STATUS');
   OUT_NUM TIMESTAMP          EQUIP_NAME EVENT_TYPE COMMENTS   NAME     
---------- ------------------ ---------- ---------- ---------- ----------
     12345 02/11/2013 11:03              STATUS     BOOKS      LION       
     12345 02/11/2013 11:13              STATUS     BOOKS      LION       
     12345 02/11/2013 11:13              STATUS     BOOKS      LION       
     12345 02/11/2013 11:13              CAUSE      APPLE      LION       
     12345 02/11/2013 11:13              CAUSE      APPLE      LION       
     12345 02/11/2013 11:13              CAUSE      APPLE      LION       
内部クエリにXYZは、分析first_value()関数が含まれname、直接一致する値がであるかどうかを選択するために使用されます。直接一致することが実際にはない場合は、これは必要ない場合がありますnull。(仮定が間違っている場合は、 or句coalesceを調整する必要がある場合もあります)。外側のクエリは、レコードが不要なため、レコードを削除するだけです。partition byorder byXYZ
一致するレコードから値を取得するname場合は、内部クエリのフィルターを削除するだけです。
しかし、今では、null以外のレコードが複数ある可能性が高くなります。これにより、存在する場合は一致するものが得られa.feed_id、存在しない場合は「最初の」もの(アルファベット順はish)out_numが得られます。b.id代わりに、またはtableb;の他の列で注文できます。何かで注文するにtableaは、別の解決策が必要になります。とにかく一致する可能性のあるものが1つしかない場合、それは実際には問題ではなく、省略できますがorder by、とにかくそれを持っている方が良いです。
別のデータを追加するとout_num:
insert into tablea values (12346, null, 'abcd', null, to_date('02/11/2013 11:11'), 1);
insert into tablea values (12346, null, 'SUB', null, to_date('02/11/2013 11:12'), 2);
insert into tablea values (12346, null, 'XYZ', null, to_date('02/11/2013 11:13'), 6);
insert into tablea values (12346, null, 'CAUSE', 'APPLE', to_date('02/11/2013 11:14'), 4);
insert into tablea values (12346, null, 'STATUS', 'BOOKS', to_date('02/11/2013 11:15'), 5);
insert into tableb values(1, 'TIGER');
...次に、これ(フィルターが削除されただけで、今回は省略しました)は、coalesceに対して同じ答えを返します。1234512346
select * from (
    select a.out_num,
        a.timestamp,
        a.equip_name,
        a.event_type,
        a.comments,
        first_value(b.name)
            over (partition by a.out_num
                order by b.name nulls last) as name
    from tablea a
    left outer join tableb b on a.feed_id = b.id
)
where out_num = '12346'
and event_type in ('CAUSE', 'STATUS');
   OUT_NUM TIMESTAMP          EQUIP_NAME EVENT_TYPE COMMENTS   NAME     
---------- ------------------ ---------- ---------- ---------- ----------
     12346 02/11/2013 11:14              CAUSE      APPLE      TIGER      
     12346 02/11/2013 11:15              STATUS     BOOKS      TIGER      
...にTIGERリンクされているのはabcd、ではありませんXYZ。