SlideShare uma empresa Scribd logo
1 de 14
SQL> desc employee
Name                                       Null?                        Type
----------------------------------------- ------------- ----------------------------
EMPNO                                      NOT NULL            NUMBER(4)
ENAME                                                         VARCHAR2(10)
JOB                                                            NUMBER(3)
MGR                                                           NUMBER(3)
HIREDATE                                                      DATE
SAL                                                           NUMBER(8,2)
COMM                                                          NUMBER(8,2)
DEPTNO                                     NOT NULL           NUMBER(2)

SQL> desc dept
Name                                         Null?                       Type
----------------------------------------- ------------- ----------------------------
DEPTNO                                       NOT NULL NUMBER(2)
NAME                                                            VARCHAR2(10)
LOCATION                                     NOT NULL NUMBER(3)

SQL> desc location
Name                                         Null?                      Type
----------------------------------------- ------------- ----------------------------
CODE                                         NOT NULL NUMBER(3)
NAME                                         NOT NULL VARCHAR2(10)

SQL> desc job
Name                                         Null?                      Type
----------------------------------------- ------------- ----------------------------
CODE                                         NOT NULL NUMBER(3)
NAME                                         NOT NULL VARCHAR2(10)
SQL> select * from dept;

   DEPTNO AME                   LOCATION
---------- ----------------- ----------
      10          sales              1
      20          research           3
      30          accounting        4
      40          admin              2
SQL> select * from job;

     CODE         NAME
---------- ----------
       1          trainee
       2          president
       3          analyst
       4          clerck

SQL> select * from location;

     CODE         NAME
---------- ----------
       1          chicago
       2          kakinada
       3          paris
       4          hyderabad
SQL> SELECT * FROM EMPLOYEE;

EMPNO ENAME                       JOB        MGR HIREDATE SAL COMM DEPTNO
---------- ---------- ---------- ---------- --------- --------------- --------- --------- ------------
      101 PAVAN                   2                    01-JAN-10 99000                             10
      102 KUMAR                   3                    03-JUN-09 20000                             20
      103 PRADEEP                 3                    04-APR-09 40000                             30
      104 SRINIVAS                 3                   18-MAR-08 50000                             40
      105 KEERTHI                  4                   19-JUN-08 60000                              20
      106 DENNIS                  1           104      20-OCT-10 15000                500           40
      107 VISHNU                   1          104 19-JUN-09 18000                     900           10
      108 KARTHIK                  1          104      28-FEB-09 12000                 150          20
      109 KALYANI                  1          104      30-APR-10 13000               1000          30
      110 ANUSHA                   1          103      07-AUG-09 19000               1500          10
      111 SIRISHA                  1          103      08-SEP-09 13000               1200          20
      112 VENKAT                   1          103      09-OCT-09 15000                230          30
      113 RATNAM                   1          104      10-NOV-10 22000                340          40

13 rows selected.
Exercise-1
    Names of employees with a job of trainee
SQL> select ename from employee where job=(select code from job where name='trainee');

ENAME
----------
DENNIS
VISHNU
KARTHIK
KALYANI
ANUSHA
SIRISHA
VENKAT
RATNAM

8 rows selected.
     List of distinct department ids
SQL> select distinct deptno from employee;

   DEPTNO
----------
      10
      20
      30
      40
      Names of employees sorted by their joining date
SQL> select ename from employee order by hiredate;

ENAME
----------
SRINIVAS
KEERTHI
KARTHIK
PRADEEP
KUMAR
VISHNU
ANUSHA
SIRISHA
VENKAT
PAVAN
KALYANI
DENNIS
RATNAM

13 rows selected.
 Names of employees who is not a sales trainee
SQL> select ename from employee where deptno not in(select deptno from dept where
name='sales') and job=(select code from job where name='trainee');

ENAME
----------
DENNIS
KARTHIK
KALYANI
SIRISHA
VENKAT
RATNAM

6 rows selected.
     Names of employees who did not get any commission
SQL> select ename from employee where comm is null;

ENAME
----------
PAVAN
KUMAR
PRADEEP
SRINIVAS
KEERTHI
      Names of employees who do not have a manager
SQL> select ename from employee where mgr is null;

ENAME
----------
PAVAN
KUMAR
PRADEEP
SRINIVAS
KEERTHI
      Names of employees in department id 20
SQL> select ename from employee where deptno=20;

ENAME
----------
KUMAR
KEERTHI
KARTHIK
SIRISHA
 Employees with a salary of over 20000
SQL> select * from employee where sal>20000;

    EMPNO ENAME           JOB        MGR HIREDATE           SAL      COMM DEPTNO
----------
     101    PAVAN               2          01-JAN-10       99000              10
     103   PRADEEP              3           04-APR-09      40000              30
     104   SRINIVAS             3          18-MAR-08       50000              40


    EMPNO ENAME           JOB        MGR HIREDATE           SAL      COMM     DEPTNO
----------
     105   KEERTHI           4              19-JUN-08      60000              20
     113   RATNAM             1      104    10-NOV-10       22000     340    40

   Employees with a salary of over 40000, but less than 80000
SQL> select * from employee where sal between 40000 and 80000;

    EMPNO ENAME           JOB        MGR HIREDATE           SAL      COMM     DEPTNO
----------
     103   PRADEEP          3                04-APR-09      40000                 30
     104   SRINIVAS         3                18-MAR-08      50000                 40
     105   KEERTHI          4                 19-JUN-08     60000                 20


    Employees working under either Pradeep or Srinivas
SQL> select * from employee where mgr in(select empno from employee where
ename='PRADEEP' or ename='SRINIVAS');

    EMPNO ENAME           JOB        MGR HIREDATE           SAL      COMM     DEPTNO
----------
     106   DENNIS           1        104 20-OCT-10           15000     50          40
     107   VISHNU           1        104  19-JUN-09         18000     900          10
     108   KARTHIK           1        104 28-FEB-09         12000     150          20

  EMPNO ENAME            JOB        MGR HIREDATE           SAL       COMM    DEPTNO
----------
     109 KALYANI            1       104 30-APR-10         13000      1000    30
     110   ANUSHA           1       103 07-AUG-09         19000      1500    10
     111   SIRISHA          1       103 08-SEP-09         13000      1200    20

    EMPNO ENAME           JOB        MGR HIREDATE           SAL      COMM     DEPTNO
----------
     112   VENKAT           1        103    09-OCT-09      15000       230    30
     113   RATNAM           1        104    10-NOV-10      22000      340    40
8 rows selected.


    Employees who are not working under either Pradeep or Srinivas
SQL> select * from employee where mgr not in(select empno from employee where
ename='PRADEEP' or ename='SRINIVAS') or mgr is null;

    EMPNO ENAME           JOB      MGR HIREDATE          SAL      COMM     DEPTNO
----------
     101   PAVAN            2             01-JAN-10     99000                   10
     102   KUMAR             3             03-JUN-09     20000                  20
     103   PRADEEP            3            04-APR-09     40000                  30


    EMPNO ENAME           JOB      MGR HIREDATE          SAL      COMM     DEPTNO
----------
     104   SRINIVAS          3             18-MAR-08     50000                  40
     105   KEERTHI           4              19-JUN-08    60000                  20

    Employees working under Pradeep and joined before him
SQL> select * from employee where mgr=(select empno from employee where
ename='PRADEEP') and hiredate<(select hiredate from employee where ename='PRADEEP');

no rows selected
     Employees working under Pradeep or Srinivas and joined before them
SQL> select * from employee where (mgr=(select empno from employee where
ename='PRADEEP')and hiredate<(select hiredate from employee where ename='PRADEEP'))or
(mgr=(select empno from employee where ename='SRINIVAS')and hiredate<(select hiredate
from employee where ename='SRINIVAS'));

no rows selected
     Employees with more commission than salary
SQL> select * from employee where comm>sal;

no rows selected
Exercise-II
    Employees in ACCOUNTING department
SQL> select * from employee where deptno=(select deptno from dept where
name='accounting');

    EMPNO ENAME             JOB      MGR HIREDATE            SAL      COMM      DEPTNO
----------
     103   PRADEEP            3              04-APR-09      40000                 30
     109   KALYANI            1      104     30-APR-10      13000     1000        30
     112   VENKAT             1       103     09-OCT-09      15000     230        30

    List of all ANALYSTS in Kakinada area
SQL> select * from employee where job=(select code from job where name='analyst') and
deptno=(select deptno from dept where location=(select code from location where
name='kakinada'));

    EMPNO ENAME             JOB      MGR HIREDATE            SAL      COMM      DEPTNO
----------
     104   SRINIVAS            3             18-MAR-08      50000                40

   Employees in SALES department
SQL> select * from employee where deptno=(select deptno from dept where name='sales');

    EMPNO ENAME             JOB      MGR HIREDATE            SAL      COMM      DEPTNO
----------
     101   PAVAN              2               01-JAN-10     99000                 10
     107   VISHNU             1      104      19-JUN-09     18000      900        10
     110   ANUSHA             1      103     07-AUG-09      19000     1500        10


   Find the job function of Keerthi
SQL> select name from job where code=(select job from employee where ename='KEERTHI');

NAME
----------
Clerk

   All the locations having a SALES department
SQL> select name from location where code in( select location from dept where name='sales');

NAME
----------
Chicago
 The job ids of all the employees who are managers of other employees
SQL> SELECT JOB FROM EMPLOYEE WHERE EMPNO IN(SELECT MGR FROM
EMPLOYEE);

     JOB
----------
       3
       3
      All the ANALYSTS who are also managers
SQL> SELECT * FROM EMPLOYEE WHERE EMPNO IN(SELECT MGR FROM
EMPLOYEE) AND JOB=(SELECT CODE FROM JOB
WHERE NAME='analyst');

    EMPNO ENAME            JOB      MGR HIREDATE           SAL      COMM      DEPTNO
----------
     103   PRADEEP            3             04-APR-09      40000               30
     104   SRINIVAS           3             18-MAR-08      50000               40

   All the employees reporting to the PRESIDENT
SQL> select * from employee where mgr=(select code from job where name='president');

no rows selected

    All the ANALYSTS reporting to the PRESIDENT
SQL> select * from employee where mgr=(select code from job where name='president') and
job=(select code from job where name='analyst');

no rows selected

    The job functions of all the employees who are managers of other employees
SQL> select name from job where code in(select job from employee where empno in(select mgr
from employee));

NAME
----------
analyst
      Find departments(names and locations) with some employees earning less than 2000
SQL> select * from dept where deptno in(select deptno from employee where sal<2000);

no rows selected
Exercise-III
   • Employees earning more than DENNIS’s manager
       SQL> select * from employee where sal>(select sal from employee where empno=(select
       mgr from employee where ename='DENNIS'));

       EMPNO ENAME             JOB        MGR HIREDATE          SAL      COMM DEPTNO
        ----------
        101        PAVAN             2            01-JAN-10     99000              10
        105        KEERTHI           4            19-JUN-08     60000              20

   •     Employees working under DENNIS and earning more than DENNIS’s manager
         SQL> select * from employee where sal>(select sal from employee where empno=(select
         mgr from employee where ename='DENNIS'))and mgr=(select empno from employee
         where ename='DENNIS');

no rows selected

   •     Employees in SALES department with the same job as anyone in the RESEARCH
         department
         SQL> select * from employee where job in(select job from employee where
         deptno=(select deptno from dept where name='sales')) and deptno=(select deptno from
         dept where name='research');

   EMPNO ENAME                JOB        MGR HIREDATE          SAL      COMM     DEPTNO
      ----------
     108 KARTHIK                 1       104   28-FEB-09      12000      150      20
     111      SIRISHA           1        103   08-SEP-09      13000     1200      20


   •     All employees in CHICAGO area
         SQL> select * from employee where deptno=(select deptno from dept where
         location=(select code from location where name='chicago'));

   EMPNO ENAME                JOB        MGR HIREDATE          SAL      COMM     DEPTNO
     ----------

       101    PAVAN             2               01-JAN-10     99000                    10
       107    VISHNU            1        104    19-JUN-09     18000      900           10
       110    ANUSHA            1        103   07-AUG-09      19000     1500           10
• Find all the employees whose join date is the earliest
SQL> select * from employee where hiredate=(select min(hiredate) from employee);

    EMPNO ENAME              JOB      MGR HIREDATE             SAL      COMM       DEPTNO
----------
     104   SRINIVAS            3              18-MAR-08       50000                40


Exercise-IV
   • Find all the employees whose join date is the earliest in their respective departments
SQL> select * from employee where hiredate in(select min(hiredate) from employee group by
deptno);

   EMPNO ENAME               JOB      MGR HIREDATE             SAL      COMM       DEPTNO
       ----------
   103        PRADEEP          3              04-APR-09       40000                 30
   104        SRINIVAS         3             18-MAR-08        50000                 40
   105        KEERTHI          4              19-JUN-08       60000                 20


   EMPNO ENAME               JOB      MGR HIREDATE             SAL      COMM       DEPTNO
    107  VISHNU               1       104  19-JUN-09          18000      900         10

  • Find all the employees whose salary is the maximum in their respective departments
SQL> select * from employee where sal in(select max(sal) from employee group by deptno);

   EMPNO ENAME               JOB      MGR HIREDATE             SAL      COMM       DEPTNO
    101  PAVAN                2             01-JAN-10         99000                  10
    103  PRADEEP              3             04-APR-09         40000                  30
    104  SRINIVAS              3           18-MAR-08          50000                  40


   EMPNO ENAME               JOB      MGR HIREDATE             SAL      COMM       DEPTNO
    105  KEERTHI               4            19-JUN-08         60000                   20

   •   Find all the customers whose sales person is not originally a salesperson
       Don’t have any salesperson details
Exercise-V
• Find all the employees whose join date is the earliest
SQL> select * from employee where hiredate=(select min(hiredate) from employee);

    EMPNO ENAME               JOB   MGR HIREDATE           SAL      COMM     DEPTNO
----------
     104   SRINIVAS            3           18-MAR-08      50000                    40

• Find the minimum salary in the ACCOUNTING department
SQL> select min(sal) from employee where deptno=(select deptno from dept where
name='accounting');

  MIN(SAL)
----------
    13000

• Find the all the employees with the minimum salary
SQL> select * from employee where sal=(select min(sal) from employee);

    EMPNO ENAME               JOB   MGR HIREDATE           SAL      COMM     DEPTNO
----------
     108   KARTHIK              1    104    28-FEB-09     12000     150            20

• Find the maximum salary of all employees
SQL> select ename,sal+comm from employee;

ENAME            SAL+COMM
---------- ----------
PAVAN               99000
KUMAR               20000
PRADEEP             40000
SRINIVAS            50000
KEERTHI              60000
DENNIS              15500
VISHNU               18900
KARTHIK              12150
KALYANI              14000
ANUSHA                20500
SIRISHA              14200

ENAME            SAL+COMM
---------- ----------
VENKAT               15230
RATNAM               22340
13 rows selected.

• Find the maximum salary of all employees from SALES department
SQL> select ename,sal+comm from employee where deptno=(select deptno from dept where
name='sales');

ENAME            SAL+COMM
---------- ----------
PAVAN               99000
VISHNU             18900
ANUSHA             20500

• Find maximum salary of all ANALYSTs
SQL> select ename,sal+comm from employee where job=(select code from job where
name='analyst');

ENAME            SAL+COMM
---------- ----------
KUMAR               20000
PRADEEP             40000
SRINIVAS            50000

• Find all the ANALYSTs with the maximum salary among ANALYSTs
SQL> select * from employee where sal=(select max(sal) from employee where job=(select code
from job where name='analyst'));

    EMPNO ENAME             JOB      MGR HIREDATE          SAL      COMM      DEPTNO
----------
     104   SRINIVAS           3             18-MAR-08      50000      0          40

• Find total commissions paid to all employees together
SQL> select sum(comm) from employee;

 SUM(COMM)
----------
     5820
• Find total salary of all CLERKs
SQL> select sum(sal) from employee where job=(select code from job where name='clerck');

  SUM(SAL)
----------
    60000
• Find the number of ANALYSTS
SQL> select sum(sal) from employee where job=(select code from job where name='clerck');

  SUM(SAL)
----------
    60000

• Find out number of different job_id in the RESEARCH department
SQL> select count(distinct job) from employee where deptno=(select deptno from dept where
name='research');

COUNT(DISTINCT JOB)
------------------
             3
• Find employees earning more than average salary of all employees
SQL> select * from employee where sal>(select avg(sal) from employee);

    EMPNO ENAME            JOB        MGR HIREDATE           SAL      COMM    DEPTNO
----------
     101   PAVAN             2              01-JAN-10        99000       0      10
     103   PRADEEP           3              04-APR-09        40000       0      30
     104   SRINIVAS          3              18-MAR-08         50000      0      40


    EMPNO ENAME            JOB        MGR HIREDATE           SAL      COMM    DEPTNO
----------
     105   KEERTHI            4              19-JUN-08       60000       0       20

• Maximum salary of all employees
SQL> select max(sal) from employee;

  MAX(SAL)
----------
    99000
• Average salary in each department_id
SQL> select avg(sal),deptno from employee group by deptno;

  AVG(SAL) DEPTNO
---------- ----------
45333.3333            10
       26250          20
22666.6667            30
       29000          40
• No of employees with each job_id
SQL> select count(*),job from employee group by job;

  COUNT(*)            JOB
---------- ----------
       8              1
       1              2
       3              3
       1              4
• No of employees where job_id is more than 3
SQL> select count(*) from employee where job>3;

  COUNT(*)
----------
       1
• No of ANALYSTS in each department
SQL> select count(*) from employee where job=(select code from job where name='analyst')
group by de
ptno;

  COUNT(*)
----------
       1
       1
       1

Mais conteúdo relacionado

Destaque

Sql insert statement
Sql insert statementSql insert statement
Sql insert statementVivek Singh
 
AIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesAIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesDan D'Urso
 
Sql update statement
Sql update statementSql update statement
Sql update statementVivek Singh
 
MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...
MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...
MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...Ashish Saxena
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In SqlAnurag
 

Destaque (7)

Sql insert statement
Sql insert statementSql insert statement
Sql insert statement
 
AIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesAIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access Queries
 
Sql update statement
Sql update statementSql update statement
Sql update statement
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
 
MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...
MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...
MS-ACCESS:CREATE TAB(QUERY-SELECT WITH CONDITIONS, MAKE A TABLE,DELETE,APPNED...
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Sql ppt
Sql pptSql ppt
Sql ppt
 

Semelhante a Dbms print

حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلMohamed Moustafa
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Sanjay Pathak
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2Umair Amjad
 
12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntax12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntaxConnor McDonald
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with outputNexus
 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Datasiavosh kaviani
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02Angel G Diaz
 
Restricting and sorting data
Restricting and sorting data Restricting and sorting data
Restricting and sorting data HuzaifaMushtaq3
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所Hiroshi Sekiguchi
 

Semelhante a Dbms print (20)

حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
 
Sql queries
Sql queriesSql queries
Sql queries
 
Sql2
Sql2Sql2
Sql2
 
12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntax12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntax
 
Les02
Les02Les02
Les02
 
Dbms 2
Dbms 2Dbms 2
Dbms 2
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
Les02.pptx
Les02.pptxLes02.pptx
Les02.pptx
 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Data
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
 
Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Restricting and sorting data
Restricting and sorting data Restricting and sorting data
Restricting and sorting data
 
chap2 (3).ppt
chap2 (3).pptchap2 (3).ppt
chap2 (3).ppt
 
Sub Queries in oracle
Sub Queries in oracleSub Queries in oracle
Sub Queries in oracle
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 

Mais de Chaitanya Kn

Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483Chaitanya Kn
 
Jpdcs1 data leakage detection
Jpdcs1 data leakage detectionJpdcs1 data leakage detection
Jpdcs1 data leakage detectionChaitanya Kn
 
Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)Chaitanya Kn
 
(Cse cs) ads programs list
(Cse  cs) ads programs list(Cse  cs) ads programs list
(Cse cs) ads programs listChaitanya Kn
 
Fantastic trip by nasa
Fantastic trip by nasaFantastic trip by nasa
Fantastic trip by nasaChaitanya Kn
 

Mais de Chaitanya Kn (15)

Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483
 
Nano tech
Nano techNano tech
Nano tech
 
Jpdcs1 data leakage detection
Jpdcs1 data leakage detectionJpdcs1 data leakage detection
Jpdcs1 data leakage detection
 
Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
(Cse cs) ads programs list
(Cse  cs) ads programs list(Cse  cs) ads programs list
(Cse cs) ads programs list
 
Testing primer
Testing primerTesting primer
Testing primer
 
Stm unit1
Stm unit1Stm unit1
Stm unit1
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Stop complaining
Stop complainingStop complaining
Stop complaining
 
God doesn
God doesnGod doesn
God doesn
 
Os 2 cycle
Os 2 cycleOs 2 cycle
Os 2 cycle
 
Presentation1
Presentation1Presentation1
Presentation1
 
Fantastic trip by nasa
Fantastic trip by nasaFantastic trip by nasa
Fantastic trip by nasa
 

Último

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 

Último (20)

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 

Dbms print

  • 1. SQL> desc employee Name Null? Type ----------------------------------------- ------------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB NUMBER(3) MGR NUMBER(3) HIREDATE DATE SAL NUMBER(8,2) COMM NUMBER(8,2) DEPTNO NOT NULL NUMBER(2) SQL> desc dept Name Null? Type ----------------------------------------- ------------- ---------------------------- DEPTNO NOT NULL NUMBER(2) NAME VARCHAR2(10) LOCATION NOT NULL NUMBER(3) SQL> desc location Name Null? Type ----------------------------------------- ------------- ---------------------------- CODE NOT NULL NUMBER(3) NAME NOT NULL VARCHAR2(10) SQL> desc job Name Null? Type ----------------------------------------- ------------- ---------------------------- CODE NOT NULL NUMBER(3) NAME NOT NULL VARCHAR2(10) SQL> select * from dept; DEPTNO AME LOCATION ---------- ----------------- ---------- 10 sales 1 20 research 3 30 accounting 4 40 admin 2
  • 2. SQL> select * from job; CODE NAME ---------- ---------- 1 trainee 2 president 3 analyst 4 clerck SQL> select * from location; CODE NAME ---------- ---------- 1 chicago 2 kakinada 3 paris 4 hyderabad SQL> SELECT * FROM EMPLOYEE; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- ---------- ---------- --------- --------------- --------- --------- ------------ 101 PAVAN 2 01-JAN-10 99000 10 102 KUMAR 3 03-JUN-09 20000 20 103 PRADEEP 3 04-APR-09 40000 30 104 SRINIVAS 3 18-MAR-08 50000 40 105 KEERTHI 4 19-JUN-08 60000 20 106 DENNIS 1 104 20-OCT-10 15000 500 40 107 VISHNU 1 104 19-JUN-09 18000 900 10 108 KARTHIK 1 104 28-FEB-09 12000 150 20 109 KALYANI 1 104 30-APR-10 13000 1000 30 110 ANUSHA 1 103 07-AUG-09 19000 1500 10 111 SIRISHA 1 103 08-SEP-09 13000 1200 20 112 VENKAT 1 103 09-OCT-09 15000 230 30 113 RATNAM 1 104 10-NOV-10 22000 340 40 13 rows selected.
  • 3. Exercise-1  Names of employees with a job of trainee SQL> select ename from employee where job=(select code from job where name='trainee'); ENAME ---------- DENNIS VISHNU KARTHIK KALYANI ANUSHA SIRISHA VENKAT RATNAM 8 rows selected.  List of distinct department ids SQL> select distinct deptno from employee; DEPTNO ---------- 10 20 30 40  Names of employees sorted by their joining date SQL> select ename from employee order by hiredate; ENAME ---------- SRINIVAS KEERTHI KARTHIK PRADEEP KUMAR VISHNU ANUSHA SIRISHA VENKAT PAVAN KALYANI DENNIS RATNAM 13 rows selected.
  • 4.  Names of employees who is not a sales trainee SQL> select ename from employee where deptno not in(select deptno from dept where name='sales') and job=(select code from job where name='trainee'); ENAME ---------- DENNIS KARTHIK KALYANI SIRISHA VENKAT RATNAM 6 rows selected.  Names of employees who did not get any commission SQL> select ename from employee where comm is null; ENAME ---------- PAVAN KUMAR PRADEEP SRINIVAS KEERTHI  Names of employees who do not have a manager SQL> select ename from employee where mgr is null; ENAME ---------- PAVAN KUMAR PRADEEP SRINIVAS KEERTHI  Names of employees in department id 20 SQL> select ename from employee where deptno=20; ENAME ---------- KUMAR KEERTHI KARTHIK SIRISHA
  • 5.  Employees with a salary of over 20000 SQL> select * from employee where sal>20000; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 101 PAVAN 2 01-JAN-10 99000 10 103 PRADEEP 3 04-APR-09 40000 30 104 SRINIVAS 3 18-MAR-08 50000 40 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 105 KEERTHI 4 19-JUN-08 60000 20 113 RATNAM 1 104 10-NOV-10 22000 340 40  Employees with a salary of over 40000, but less than 80000 SQL> select * from employee where sal between 40000 and 80000; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 103 PRADEEP 3 04-APR-09 40000 30 104 SRINIVAS 3 18-MAR-08 50000 40 105 KEERTHI 4 19-JUN-08 60000 20  Employees working under either Pradeep or Srinivas SQL> select * from employee where mgr in(select empno from employee where ename='PRADEEP' or ename='SRINIVAS'); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 106 DENNIS 1 104 20-OCT-10 15000 50 40 107 VISHNU 1 104 19-JUN-09 18000 900 10 108 KARTHIK 1 104 28-FEB-09 12000 150 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 109 KALYANI 1 104 30-APR-10 13000 1000 30 110 ANUSHA 1 103 07-AUG-09 19000 1500 10 111 SIRISHA 1 103 08-SEP-09 13000 1200 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 112 VENKAT 1 103 09-OCT-09 15000 230 30 113 RATNAM 1 104 10-NOV-10 22000 340 40
  • 6. 8 rows selected.  Employees who are not working under either Pradeep or Srinivas SQL> select * from employee where mgr not in(select empno from employee where ename='PRADEEP' or ename='SRINIVAS') or mgr is null; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 101 PAVAN 2 01-JAN-10 99000 10 102 KUMAR 3 03-JUN-09 20000 20 103 PRADEEP 3 04-APR-09 40000 30 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 104 SRINIVAS 3 18-MAR-08 50000 40 105 KEERTHI 4 19-JUN-08 60000 20  Employees working under Pradeep and joined before him SQL> select * from employee where mgr=(select empno from employee where ename='PRADEEP') and hiredate<(select hiredate from employee where ename='PRADEEP'); no rows selected  Employees working under Pradeep or Srinivas and joined before them SQL> select * from employee where (mgr=(select empno from employee where ename='PRADEEP')and hiredate<(select hiredate from employee where ename='PRADEEP'))or (mgr=(select empno from employee where ename='SRINIVAS')and hiredate<(select hiredate from employee where ename='SRINIVAS')); no rows selected  Employees with more commission than salary SQL> select * from employee where comm>sal; no rows selected
  • 7. Exercise-II  Employees in ACCOUNTING department SQL> select * from employee where deptno=(select deptno from dept where name='accounting'); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 103 PRADEEP 3 04-APR-09 40000 30 109 KALYANI 1 104 30-APR-10 13000 1000 30 112 VENKAT 1 103 09-OCT-09 15000 230 30  List of all ANALYSTS in Kakinada area SQL> select * from employee where job=(select code from job where name='analyst') and deptno=(select deptno from dept where location=(select code from location where name='kakinada')); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 104 SRINIVAS 3 18-MAR-08 50000 40  Employees in SALES department SQL> select * from employee where deptno=(select deptno from dept where name='sales'); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 101 PAVAN 2 01-JAN-10 99000 10 107 VISHNU 1 104 19-JUN-09 18000 900 10 110 ANUSHA 1 103 07-AUG-09 19000 1500 10  Find the job function of Keerthi SQL> select name from job where code=(select job from employee where ename='KEERTHI'); NAME ---------- Clerk  All the locations having a SALES department SQL> select name from location where code in( select location from dept where name='sales'); NAME ---------- Chicago
  • 8.  The job ids of all the employees who are managers of other employees SQL> SELECT JOB FROM EMPLOYEE WHERE EMPNO IN(SELECT MGR FROM EMPLOYEE); JOB ---------- 3 3  All the ANALYSTS who are also managers SQL> SELECT * FROM EMPLOYEE WHERE EMPNO IN(SELECT MGR FROM EMPLOYEE) AND JOB=(SELECT CODE FROM JOB WHERE NAME='analyst'); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 103 PRADEEP 3 04-APR-09 40000 30 104 SRINIVAS 3 18-MAR-08 50000 40  All the employees reporting to the PRESIDENT SQL> select * from employee where mgr=(select code from job where name='president'); no rows selected  All the ANALYSTS reporting to the PRESIDENT SQL> select * from employee where mgr=(select code from job where name='president') and job=(select code from job where name='analyst'); no rows selected  The job functions of all the employees who are managers of other employees SQL> select name from job where code in(select job from employee where empno in(select mgr from employee)); NAME ---------- analyst  Find departments(names and locations) with some employees earning less than 2000 SQL> select * from dept where deptno in(select deptno from employee where sal<2000); no rows selected
  • 9. Exercise-III • Employees earning more than DENNIS’s manager SQL> select * from employee where sal>(select sal from employee where empno=(select mgr from employee where ename='DENNIS')); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 101 PAVAN 2 01-JAN-10 99000 10 105 KEERTHI 4 19-JUN-08 60000 20 • Employees working under DENNIS and earning more than DENNIS’s manager SQL> select * from employee where sal>(select sal from employee where empno=(select mgr from employee where ename='DENNIS'))and mgr=(select empno from employee where ename='DENNIS'); no rows selected • Employees in SALES department with the same job as anyone in the RESEARCH department SQL> select * from employee where job in(select job from employee where deptno=(select deptno from dept where name='sales')) and deptno=(select deptno from dept where name='research'); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 108 KARTHIK 1 104 28-FEB-09 12000 150 20 111 SIRISHA 1 103 08-SEP-09 13000 1200 20 • All employees in CHICAGO area SQL> select * from employee where deptno=(select deptno from dept where location=(select code from location where name='chicago')); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 101 PAVAN 2 01-JAN-10 99000 10 107 VISHNU 1 104 19-JUN-09 18000 900 10 110 ANUSHA 1 103 07-AUG-09 19000 1500 10
  • 10. • Find all the employees whose join date is the earliest SQL> select * from employee where hiredate=(select min(hiredate) from employee); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 104 SRINIVAS 3 18-MAR-08 50000 40 Exercise-IV • Find all the employees whose join date is the earliest in their respective departments SQL> select * from employee where hiredate in(select min(hiredate) from employee group by deptno); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 103 PRADEEP 3 04-APR-09 40000 30 104 SRINIVAS 3 18-MAR-08 50000 40 105 KEERTHI 4 19-JUN-08 60000 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 107 VISHNU 1 104 19-JUN-09 18000 900 10 • Find all the employees whose salary is the maximum in their respective departments SQL> select * from employee where sal in(select max(sal) from employee group by deptno); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 101 PAVAN 2 01-JAN-10 99000 10 103 PRADEEP 3 04-APR-09 40000 30 104 SRINIVAS 3 18-MAR-08 50000 40 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 105 KEERTHI 4 19-JUN-08 60000 20 • Find all the customers whose sales person is not originally a salesperson Don’t have any salesperson details
  • 11. Exercise-V • Find all the employees whose join date is the earliest SQL> select * from employee where hiredate=(select min(hiredate) from employee); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 104 SRINIVAS 3 18-MAR-08 50000 40 • Find the minimum salary in the ACCOUNTING department SQL> select min(sal) from employee where deptno=(select deptno from dept where name='accounting'); MIN(SAL) ---------- 13000 • Find the all the employees with the minimum salary SQL> select * from employee where sal=(select min(sal) from employee); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 108 KARTHIK 1 104 28-FEB-09 12000 150 20 • Find the maximum salary of all employees SQL> select ename,sal+comm from employee; ENAME SAL+COMM ---------- ---------- PAVAN 99000 KUMAR 20000 PRADEEP 40000 SRINIVAS 50000 KEERTHI 60000 DENNIS 15500 VISHNU 18900 KARTHIK 12150 KALYANI 14000 ANUSHA 20500 SIRISHA 14200 ENAME SAL+COMM ---------- ---------- VENKAT 15230 RATNAM 22340
  • 12. 13 rows selected. • Find the maximum salary of all employees from SALES department SQL> select ename,sal+comm from employee where deptno=(select deptno from dept where name='sales'); ENAME SAL+COMM ---------- ---------- PAVAN 99000 VISHNU 18900 ANUSHA 20500 • Find maximum salary of all ANALYSTs SQL> select ename,sal+comm from employee where job=(select code from job where name='analyst'); ENAME SAL+COMM ---------- ---------- KUMAR 20000 PRADEEP 40000 SRINIVAS 50000 • Find all the ANALYSTs with the maximum salary among ANALYSTs SQL> select * from employee where sal=(select max(sal) from employee where job=(select code from job where name='analyst')); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 104 SRINIVAS 3 18-MAR-08 50000 0 40 • Find total commissions paid to all employees together SQL> select sum(comm) from employee; SUM(COMM) ---------- 5820 • Find total salary of all CLERKs SQL> select sum(sal) from employee where job=(select code from job where name='clerck'); SUM(SAL) ---------- 60000
  • 13. • Find the number of ANALYSTS SQL> select sum(sal) from employee where job=(select code from job where name='clerck'); SUM(SAL) ---------- 60000 • Find out number of different job_id in the RESEARCH department SQL> select count(distinct job) from employee where deptno=(select deptno from dept where name='research'); COUNT(DISTINCT JOB) ------------------ 3 • Find employees earning more than average salary of all employees SQL> select * from employee where sal>(select avg(sal) from employee); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 101 PAVAN 2 01-JAN-10 99000 0 10 103 PRADEEP 3 04-APR-09 40000 0 30 104 SRINIVAS 3 18-MAR-08 50000 0 40 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- 105 KEERTHI 4 19-JUN-08 60000 0 20 • Maximum salary of all employees SQL> select max(sal) from employee; MAX(SAL) ---------- 99000 • Average salary in each department_id SQL> select avg(sal),deptno from employee group by deptno; AVG(SAL) DEPTNO ---------- ---------- 45333.3333 10 26250 20 22666.6667 30 29000 40
  • 14. • No of employees with each job_id SQL> select count(*),job from employee group by job; COUNT(*) JOB ---------- ---------- 8 1 1 2 3 3 1 4 • No of employees where job_id is more than 3 SQL> select count(*) from employee where job>3; COUNT(*) ---------- 1 • No of ANALYSTS in each department SQL> select count(*) from employee where job=(select code from job where name='analyst') group by de ptno; COUNT(*) ---------- 1 1 1