Maxson Ndlovu
Maxson Ndlovu

Reputation: 207

Oracle DATE - Check if date is IN a set of years

I have an employee table and I want to count the number of employees that were hired on certain years. E.g 2010, 2013, 2014 and 2016..

So far I have something like:

SELECT COUNT(*) FROM employees WHERE hire_date IN(2010, 2013, 2014, 2016);

Upvotes: 0

Views: 1070

Answers (1)

Maxson Ndlovu
Maxson Ndlovu

Reputation: 207

Okay I got it..

All I had to do was to extract a year from hire_date.

SELECT COUNT(*) 
FROM   employees
WHERE  extract(YEAR FROM hire_date) IN (2003, 2004, 2006, 2008);

Upvotes: 5

Related Questions