I'd like to write a query to retrieve users' id
whose birthyear
is in current year or all the years which have increment of -12 from Health_User
table. Take this year for example, it would be users who were born in 2018, 2006, 1994, 1982... I want the query to be general enough to be used in any year without resetting the current year.
My approach is written below:
CREATE SEQUENCE years MAXVALUE EXTRACT (YEAR FROM current_date) INCREMENT -12;
SELECT id, EXTRACT (YEAR FROM birthyear)
FROM Health_User
WHERE EXTRACT (YEAR FROM birthyear) IN (years);
birthyear
in Health_User
is a column in timestamp date format (thanks to Erwin Brandstetter's reminder) which is always January 1st of the year in which the user was born.
However, it returns an error reads: "syntax error at or near 'EXTRACT'" in the first line. Would someone suggest how I can revise my query?
Have read: