Hello I'm trying to join two tables in bigquery using two fields, one of them is a date field and the other a currency_code.
Example data:
sales_table
|sales_id|currency| date |value|
|1234 |GBP |2020-01-10| 1.50|
|1235 |GBP |2020-01-15| 1.48|
|1236 |GBP |2020-01-20| 1.49|
currency_table
|currency| date | rate|
|GBP |2020-01-10| 0.89|
|GBP |2020-01-15| 0.89|
|GBP |2020-01-19| 0.89|
The idea is to get the exchange_rate for a particular date
I don't always have all the dates on currency_table so I would like to join on nearest value.
How can I achieve this?
I tried using CROSS JOIN but the size of the data (5M Rows on sales table) makes it almost impossible to work with.
Any ideas?