cid name dob(timstamp dtype) 101 x 11-02-2019 301 y 12-12-2019 901 z 21-07-2018 111 a 02-07-2020
this is my table. i want to extract records of last 1 year from current date. so my output should be
cid name dob 101 x 11-02-2019 301 y 12-12-2019 111 a 02-07-2020
Advertisement
Answer
In the WHERE
clause set the condition that dob
is greater than the current date minus 1 year:
select * from tablename where dob >= current_date - 1 year
If you want all the rows of the current and the previous year:
select * from tablename where year(current_date) - year(dob) in (0, 1)
See the demo.