I am going through a practice worksheet with questions and expected outputs. The last question is proving to be difficult for me to grasp. Can anyone help please.
Question
Create a query to display the total number of employees and, of that total, the number of employees hired in 2005, 2006, 2007 and 2008.
Expected output format
Total 2005 2006 2007 2008
107 29 24 19 11
The following are my attempts to get the results with separate queries
TO_CHAR(hire_date,'YYYY')
SELECT COUNT(employee_id) AS "Total"
FROM employees;
SELECT COUNT(employee_id) AS "2005"
FROM employees
WHERE TO_CHAR(hire_date,'YYYY') LIKE '2005' GROUP BY TO_CHAR(hire_date,'YYYY') ;
SELECT COUNT(employee_id) AS "2006"
FROM employees
WHERE TO_CHAR(hire_date,'YYYY') LIKE '2006' GROUP BY TO_CHAR(hire_date,'YYYY') ;
SELECT COUNT(employee_id) AS "2007"
FROM employees
WHERE TO_CHAR(hire_date,'YYYY') LIKE '2007' GROUP BY TO_CHAR(hire_date,'YYYY') ;
SELECT COUNT(employee_id) AS "2008"
FROM employees
WHERE TO_CHAR(hire_date,'YYYY') LIKE '2008' GROUP BY TO_CHAR(hire_date,'YYYY') ;
Any help producing the result as one query is greatly appreciated.
SELECT COUNT(*) AS numEmpls, TO_CHAR(hire_date,'YYYY') AS theYear FROM employees GROUP BY TO_CHAR(hire_date,'YYYY')