Sql, which gives the number of employees hired in the same month (or year) grouped and sequentially on date basis.
I tried to write this code, but i didn’t find same hired and order.
x
SELECT hire_date,COUNT(hire_date)
FROM employees
GROUP BY hire_date;
Advertisement
Answer
This is how I understood the question.
Sample data:
SQL> select ename, hiredate from emp order by hiredate;
ENAME HIREDATE
---------- ----------
SMITH 17_12_1980
ALLEN 20_02_1981
WARD 22_02_1981
JONES 02_04_1981
BLAKE 01_05_1981
CLARK 09_06_1981
TURNER 08_09_1981
MARTIN 28_09_1981
KING 17_11_1981
JAMES 03_12_1981
FORD 03_12_1981
MILLER 23_01_1982
SCOTT 09_12_1982
ADAMS 12_01_1983
14 rows selected.
Employed in the same month:
SQL> select to_char(hiredate, 'mm.yyyy') hire_month,
2 count(*)
3 from emp
4 group by to_char(hiredate, 'mm.yyyy')
5 order by 1;
HIRE_MO COUNT(*)
------- ----------
01.1982 1
01.1983 1
02.1981 2
04.1981 1
05.1981 1
06.1981 1
09.1981 2
11.1981 1
12.1980 1
12.1981 2
12.1982 1
11 rows selected.
SQL>
Hired in the same year:
SQL> select extract(year from hiredate) hire_year,
2 count(*)
3 from emp
4 group by extract(year from hiredate)
5 order by 1;
HIRE_YEAR COUNT(*)
---------- ----------
1980 1
1981 10
1982 2
1983 1
SQL>