Relative Content

Tag Archive for sqlapache-spark-sql

Fill value from previous date if current date is not availables

I have two tables – sales and currency_rate. I want to fill col CurrRate to each transaction line from Sales based on the the month as from table sales col [Date] and table currency_rate col CurrentPeriod. If it happens that chain of dates is break in the table currency_rate I want to fill previous CurrRate value of previous month to the actual line of Sales. What is worth to mention that both CurrentPeriod and PreviousPeriod are datetime and Date in table Sales is int like 20240701