I have a need to join a table to itself. I need to determine if for a given deal number the swap deal number does not exist on the table. Here is my query thus far, but it is really dogging. Is there a better approach ??
select a.counter_ccy,
a.value_date,
sum(a.counter_amt) * -1
from trade_data a
where a.branch = 'NY' and
a.deal_type = 'SELL' and
not exists (select 1 from trade_data b where b.deal_num = a.swap_deal_num and b.ticket_area = a.ticket_area)
group by a.currency, a.value_date
select a.counter_ccy,
a.value_date,
sum(a.counter_amt) * -1
from trade_data a
where a.branch = 'NY' and
a.deal_type = 'SELL' and
not exists (select 1 from trade_data b where b.deal_num = a.swap_deal_num and b.ticket_area = a.ticket_area)
group by a.currency, a.value_date