I'm trying to get data from Current year and last three years. (2022,2021,2020, 2019) I've a year field which is number. For now I hard-coded value in my code as Year >= 2019.
I need help on how to make this dynamic so in future I just get data of past three years from the current year(included). (Eg: If the current year is 2025, I will get data of 2025,2024,2023,2022)
CodePudding user response:
Can you try this?
SELECT *
FROM yourtable WHERE colyear >= YEAR( current_date() ) - 3;
CURRENT_DATE: https://docs.snowflake.com/en/sql-reference/functions/current_date.html
YEAR: https://docs.snowflake.com/en/sql-reference/functions/year.html