-- Databricks notebook source
/*
修改日期：20250311
修改人：chenwu
修改内容：取sales表中最大日期的年
*/
insert OVERWRITE dm.dm_td_external_exchangerate (
  from_currency_id, to_currency_id, az_year, exchange_rate, etl_update_dt, etl_insert_dt
)
  select
    from_currency_id,
    to_currency_id,
    az_year,
    exchange_rate,
    etl_update_dt,
    etl_insert_dt
  from
    dm.DM_TD_EXCHANGE_RATE
  where
    AZ_YEAR in (
      select
        left(max(YYYYMM), 4)
      from
        dm.dm_tf_external_sales --取sales表中最大日期的年
    )
    AND FROM_CURRENCY_ID = 'USD'