Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Venkat.

Asked: October 26, 2016 - 3:56 am UTC

Last updated: November 04, 2016 - 6:58 am UTC

Version: oracle11g

Viewed 1000+ times

You Asked

hello,
i have two tables DEPARTMENT_DETAILS(deptno,dname,loc) and EMPLOYEE_DETAILS(empno,ename,job,sal,mgr,comm,deptno) with having data 5 records in department_details and 14 records in employee table


my query is that....
i wnat to display the department number(i.e deptno) where more than two clerks are working..?

thanks in advance...


and Connor said...

I've done "2 or more" but you get the idea

SQL> select * from scott.emp order by deptno;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500                    30
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30

14 rows selected.

SQL>
SQL> select deptno
  2  from scott.emp
  3  where job = 'CLERK'
  4  group by deptno
  5  having count(*) >= 2;

    DEPTNO
----------
        20

1 row selected.



Is this answer out of date? If it is, please let us know via a Comment