Skip to content
Advertisement

Postgres – how to displays data for the previous year?

I have sql

tanggal is date 2021-01-01

I want to display previous year’s data for example in 2020, how to write the correct query?

Advertisement

Answer

Using your method:

However, I prefer to avoid functions on the column — so the query is easier to optimize. So I would recommend:

This just uses now() rather than current_date because it is easier to type.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement