This sql query is to convert from a year to the century of this... what happens is that for cases that are years that are multiples of 100 it does not work for me since Eg: 1900 belongs to the last year of the 19th century, just like 2000 to the 20th century, etc... and my problem is that I don't know how to put the if conditions in sql in case the module yr/100=0
does something, or else keep my yr/100+1
...
select (yr/100+1) as century from years
This image is from my query for the years 1705, 1923, 1600, 2000, 444 and 88 respectively...
I am using PostgreSQL 9.6
the table is years and the column yr
Use directly
date_part()
indicating as a parametercentury
:In case you only have one year as data, you could do: