0

I have built this query (snapshot attached) to check if there is any staleness in prices by comparing today's price with previous day price for certain timezones, what i need is it should only throw only that object_id which shows '0' as BP_move for the mentioned timezones. for eg in the snapshot we can see that AED fx price is 0 for across all the timezones so it is acceptable but other ccy like EUR, GHS ,KES ,NZD and QAR are stale only for one or two timezones so those should not get published in output. is there any if condition i can use in this query ?

select distinct
    vyc.asof, vyc.timezone, vyc.object_id, i.name, 
    vpf.rate * 100 todays_rate, vpf2.rate * 100 prior_rate, 
    (vpf.rate - vpf2.rate) * 1000 bp_move 
from
    val_yield_curves vyc
inner join 
    val_prices_fx vpf on vyc.asof = vpf.asof 
                      and vyc.rowkey = vpf.curve
inner join 
    val_yield_curves vyc2 on vyc.timezone = vyc2.timezone 
                          and vyc2.asof = case when to_char(sysdate,'DY') = 'MON' then trunc(sysdate-3) else trunc(sysdate-1) end 
                          and vyc.object_id = vyc2.object_id
inner join 
    val_prices_fx vpf2 on vyc2.asof = vpf2.asof 
                       and vyc2.rowkey = vpf2.curve 
                       and vpf.instrument = vpf2.instrument
inner join 
    instruments i on i.pkey = vpf.instrument
where 
    vyc.object_id like '%Spot%' 
    and vyc.timezone in ('L0200', 'L1000', 'L1200', 'L1500')
    and (vpf.rate - vpf2.rate) * 1000 in '0'
    and vyc.asof = trunc(sysdate)
order by 
    vyc.object_id

enter image description here

2
  • 1
    Tag only the database that you use. Commented Jul 13, 2021 at 14:19
  • Join with a subquery that returns the object IDs that fit your criteria. Commented Jul 13, 2021 at 14:23

1 Answer 1

1

I don't know if I understood correctly your problem but...

If you don't need timezone information, you can

  • GROUP BY object_id, name, rates
  • HAVING COUNT(DISTINCT Timezone) >= 4

If you need timezone information, you can add a "OBJECT_ID IN (SELECT...)" condition in your WHERE. You have to make it check if you have the right number of lines for your OBJECT_ID. You can GROUP BY/HAVING COUNT this subrequest as above and returns OBJECT_ID.

Sign up to request clarification or add additional context in comments.

2 Comments

can you pls share an example ?
i only need those object_ids which have 0 value against all the input timezone ('L0200', 'L1000','L1200','L1500)'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.