vgrabovets
11/2/2016 - 8:34 AM

exchange rate

exchange rate

create or replace view test.vg_exch_rate as
SELECT
  currency_id
, to_usd
, YEAR(date) * 100 + MONTH(date)                                        month_id
, TIMESTAMP
  (ADDDATE(LAST_DAY(ADDDATE(date, INTERVAL -1 MONTH)), INTERVAL 1 DAY)) date_start
, TIMESTAMP(date, '23:59:59')                                           date_end
FROM
  megogo_db.currency_daily
HAVING month_id <> 201609 UNION SELECT
  currency_id
, to_usd
, YEAR(date) * 100 + MONTH(date)                                        month_id
, TIMESTAMP
  (ADDDATE(LAST_DAY(ADDDATE(date, INTERVAL -1 MONTH)), INTERVAL 1 DAY)) date_start
, TIMESTAMP(date, '23:59:59')                                           date_end
FROM
  test.currency_201609
HAVING month_id = 201609;