Ethan Ethan - 4 months ago 10
SQL Question

SQL - Count rows based on 2 restrictions

I have an

employees
table with a
hire_date
column and the query I'm trying to make is to count how many employees were hired in 1995 and 1996. Where 1995 has its own column and 1996 has its own column:

______________
| | |
| 1995 | 1996 |
|______|______|
| 2 | 3 |
|______|______|


Pseudocode:
display COUNT of rows WHERE hire_date LIKE '%95', display COUNT of rows WHERE hire_date LIKE '%96'


Could anyone guide me as to how I can achieve this?

Answer
SELECT (SELECT COUNT(*) FROM employees WHERE hire_date = '1995') "1995",
       (SELECT COUNT(*) FROM employees WHERE hire_date = '1996') "1996"
FROM dual;
Comments