SQL Query to find the department (ID) wise counts in the company

Write SQL Query to find the department (ID) wise counts in the company.
Schema "employee" contains "employee_id", "employee_name", "dept_id".

Questions by Neel Gurbani

Showing Answers 1 - 7 of 7 Answers

vinay

  • Jul 9th, 2015
 

Code
  1. SELECT deptno, count(deptno)

  2. FROM emp

  3. GROUP BY deptno;

  Was this answer useful?  Yes

vinay

  • Jul 11th, 2015
 

Code
  1.  

  2. SELECT a.empno,

  3. a.ename,

  4. a.deptno AS "DEPT ID",

  5. b.dname,

  6. COUNT(a.deptno) over (partition BY a.deptno ORDER BY 1) count_dept

  7. FROM scott.emp a,

  8. scott.dept b

  9. WHERE a.deptno = b.deptno

  Was this answer useful?  Yes

Abhilash Choudhary

  • Oct 5th, 2015
 

Code
  1. SELECT E.Empno, E.Ename, E1.Deptno, E1.Leastsal

  2. FROM Emp E,(SELECT Deptno,COUNT(Deptno) Leastsal

  3.                     FROM Emp

  4.                     GROUP BY Deptno) E1

  5. WHERE E.Deptno = E1.Deptno

  6. ORDER BY Deptno

  Was this answer useful?  Yes

Preetish

  • Dec 23rd, 2015
 

Code
  1. SELECT d.dept_name , count(e.emp_no)

  2. FROM dept d,emp e

  3. WHERE d.dept_no=e.dept_no

  4. GROUP BY d.dept_no;

  Was this answer useful?  Yes

M JAGADADEESH

  • Mar 9th, 2016
 

Code
  1. SELECT DEPTNO,COUNT(EMPNO) FROM EMP GROUP BY DEPTNO

  Was this answer useful?  Yes

Code
  1. WITH EMP2 AS(

  2.    SELECT DEPTNO,COUNT(*) LASAL

  3.     FROM EMP

  4.     GROUP BY DEPTNO)

  5. SELECT E.EMPNO,E.ENAME,E.DEPTNO,E2.LASAL

  6.  FROM EMP E ,(SELECT * FROM EMP2) E2

  7. WHERE E.DEPTNO = E2.DEPTNO ORDER BY E.DEPTNO;

  8.  

  9. 7782    CLARK   10      3

  10. 7839    KING    10      3

  11. 7934    MILLER  10      3

  12. 7566    JONES   20      5

  13. 7902    FORD    20      5

  14. 7876    ADAMS   20      5

  15. 7369    SMITH   20      5

  16. 7788    SCOTT   20      5

  17. 7521    WARD    30      6

  18. 7844    TURNER  30      6

  19. 7499    ALLEN   30      6

  20. 7900    JAMES   30      6

  21. 7698    BLAKE   30      6

  22. 7654    MARTIN  30      6

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions