Hi Arup,
Two ways come to mind for me. They're pretty much the same as Szymon's, just minus the sample table creation. I would suggest creating a view instead, so you can just select from it whenever you please.
create view vw_employee as
select * from employees
where ((age(joining_date::date) like '5 years%') or (age(joining_date::date) like '10 years%') )
or
create view vw_employee as
select * from employees
where
((to_char(joining_date, 'YYYY-MM') = to_char((now() - interval '5 years'), 'YYYY-MM') )
or
(to_char(joining_date, 'YYYY-MM') = to_char((now() - interval '10 years'), 'YYYY-MM')))
And then to check the employees who have completed 5 or 10 years, you'll just do:
select * from vw_employee
This is done off the top of my head so there will likely be syntax errors, but I hope this can give you a general idea.
- Rebecca