i have this table:
name dob Peter 1914-07-23 John 1990-03-25 Sandra 2014-07-23 Sam 1911-01-01 Jane 2011-01-01 Tom 2017-01-01
How do I fetch a list of Persons who have the same dob and exactly 100 years older or younger?
Expected rows:
name dob Peter 1914-07-23 Sandra 2014-07-23 Sam 1911-01-01 Jane 2011-01-01
The difference between dob should be 100 years
Advertisement
Answer
If the DOB is a date data type, would suggest using TRUNC
and ADD_MONTHS
.
SELECT a.name FROM my_table a, my_table b WHERE TRUNC(a.dob) = TRUNC(ADD_MONTHS(b.dob, 100*12))