I have a table in postgres
one of the columns is year which is calculated as :
date_part('year',current_date) + generate_series(-2,4)
so if I take today’s date , the output will be :
| year |
|---|
| 2021 |
| 2025 |
| 2019 |
| 2024 |
| 2023 |
| 2022 |
| 2020 |
How to achieve the above in snowflake environment.
Thanks in advance
>Solution :
SELECT DATEADD(year, (ROW_NUMBER() OVER(ORDER BY seq8())-3, current_date) AS y,
FROM TABLE(GENERATOR(ROWCOUNT => 7));
And year only:
SELECT YEAR(CURRENT_DATE) + (ROW_NUMBER() OVER(ORDER BY seq8())-3 AS y,
FROM TABLE(GENERATOR(ROWCOUNT => 7));