あなたはすべての行の完全な詳細だけではなく、注文番号が必要な場合は、その後、あなたは分析関数を使用する必要があります集合体ではなく、この場合、行の条件付き解析カウントはtest_data=400
です。
with
test_data (status_id, order_number) as (
select 100, 'ord1' from dual union all
select 200, 'ord2' from dual union all
select 100, 'ord3' from dual union all
select 300, 'ord2' from dual union all
select 100, 'ord4' from dual union all
select 400, 'ord2' from dual union all
select 200, 'ord1' from dual union all
select 200, 'ord3' from dual
)
-- end of test data (not part of the query); SQL query begins below this line
select status_id, order_number
from (select status_id, order_number,
count(case when status_id = 400 then 1 end)
over (partition by order_number) as st_400_cnt
from test_data
)
where status_id in (100, 200)
and st_400_cnt = 0
order by order_number, status_id -- if needed
;
STATUS_ID ORDER_NUMBER
--------- ------------
100 ord1
200 ord1
100 ord3
200 ord3
100 ord4
5 rows selected.
あなたの要件を満たす注文には、「order_number」だけを表示する必要がありますか、または行全体を表示する必要がありますか(つまり、status_idを含む)ですか? – mathguy
実際の要件は、status_id、Order_number、order_date、account_numberなどを含む行全体を表示することです。代わりに、上記のクエリからorder_numberを収集してから、すべての情報を取得するためにテーブルを再クエリします。私の知識のために、より単純な解決策があれば、素晴らしいことになるでしょう。 Mathguyに感謝します。 –
これは、望む結果を得るには非常に非効率的な方法です。 – mathguy