Skip to content
Advertisement

Tag: partition-by

Return last year value with last_value function in SQL

I need to return the last value of the last date of the year. the problem is that the last value that already comes in SQL is being returned. Product Date Value Last_Value_Previous_Year Prod A 31/12/2020 5000.00 2000.00 Prod A 01/01/2020 2000.00 2000.00 Prod A 01/01/2021 1000.00 3000.00 Prod A 01/02/2021 1500.00 3000.00 Prod A 01/03/2021 1000.00 3000.00 Prod A

Advertisement