Advertisement
Guest User

Untitled

a guest
May 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select tr.rate_sale, tr.rate_buy,  to_char(tr.buy_start_time, 'DD.MM.YYYY hh:mm' ) as buy_start_time,
  2.               to_char(tr.sale_start_time, 'DD.MM.YYYY hh:mm' ) as sale_start_time
  3.                 from t_subject ts1
  4.                   inner join t_rate tr on tr.subject_id = ts1.subject_id
  5.                   inner join t_currency tc on tc.currency_id = tr.currency
  6.                     where ts1.subject_id = 1713 and tc.brief = 'USD'
  7.                     and tr.active = true
  8.                     and tr.buy_start_time <= (now())
  9.                     and buy_start_time = (select r2.buy_start_time from t_rate r2 where r2.active = true and r2.subject_id = 1713 and r2.currency = tc.currency_id order by r2.buy_start_time desc limit 1)
  10.                     and tr.sale_start_time <= (now())
  11.                     and tr.sale_start_time = (select r3.sale_start_time from t_rate r3 where r3.active = true and r3.subject_id = 1713 and r3.currency = tc.currency_id order by r3.sale_start_time desc limit 1)
  12.                     and tr.rate_type = 'manual' limit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement