114 Cs 0093
114 Cs 0093
114 Cs 0093
(
EMPNO number(4),
ENAME varchar2(10),
JOB varchar(50)NOT NULL,
MGR varchar2(9),
HIREDATE date,
SAL number(7,2),
COMM number(7,2),
DEPTNO number(2),
PRIMARY KEY (EMPNO)
);
insert all
into EMPLOYEE
values(7839,'king','president','null',DATE '2001-9-17',50000,null,10)
into EMPLOYEE
values(7698,'Blake','manager',7839,DATE '2001-5-01',28500,null,30)
into EMPLOYEE
values(7782,'Clark','manager',7839,DATE '2001-6-09',24500,null,10)
into EMPLOYEE
values(7566,'Jones','manager',7839,DATE '2001-4-2',29750,null,20)
into EMPLOYEE
values(7654,'Martin','salesman',7698,DATE '2001-9-28',12500,14000,30)
into EMPLOYEE
values(7499,'Allen','salesman',7698,DATE '2001-2-20',16000,3000,30)
into EMPLOYEE
values(7844,'Turner','salesman',7698,DATE '2001-2-8',15000,0,30)
into EMPLOYEE
values(7900,'James','clerk',7698,DATE '2001-12-3',9500,null,30)
into EMPLOYEE
values(7521,'Ward','salesman',7698,DATE '2001-2-22',12500,5000,30)
into EMPLOYEE
values(7902,'Ford','analyst',7566,DATE '2001-12-3',30000,null,null)
into EMPLOYEE
values(7369,'Smith','clerk',7902,DATE '2000-12-17',8000,null,null)
into EMPLOYEE
values(7788,'Scott','analyst',7566,DATE '2002-12-09',30000,null,20)
into EMPLOYEE
values(7876,'adams','clerk',7788,DATE '2003-1-12',11000,null,20)
into EMPLOYEE
values(7934,'Miller','clerk',7782,DATE '2002-1-23',13000,null,null)
select * from dual;
select * from EMPLOYEE;
insert all
into DEPARTMENT values(10,'Accounting','NewDelhi')
into DEPARTMENT values(20,'Research','Bombay')
into DEPARTMENT values(30,'sales','Chennai')
into DEPARTMENT values(40,'operation','kolkata')
select * from dual;
select * from DEPARTMENT;
HISAL number(7,2)
);
insert all
into SALARYGRADE values(1,7000,12000)
into SALARYGRADE values(2,12001,14000)
into SALARYGRADE values(3,14001,20000)
into SALARYGRADE values(4,20001,30000)
into SALARYGRADE values(5,30001,99999)
SELECT * from dual;
Q2.
ANS:
Sal
50000
7698 Manager
28500
7782 Manager
24500
7566 Manager
29750
7654 Salesman
12500
7499 Salesman
16000
7844 Salesman
15000
7900 Clerk
7521 Salesman
9500
12500
7902 Analyst
30000
7369 Clerk
8000
Sal
30000
7876 Clerk
11000
7934 Clerk
13000
14 rows selected.
Q3.
ANS:
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
President
17-NOV-01
50000
10
7698 Blake
Manager 7839
01-MAY-01
28500
Manager 7839
09-JUN-01
24500
30
7782 Clark
10
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
Manager 7839
02-APR-01
29750
20
7654 Martin
Salesman 7698
28-SEP-01
12500
14000
30
7499 Allen
Salesman 7698
20-FEB-01
16000
3000
HIREDATE
SAL
COMM
15000
30
EMPNO ENAME
JOB
MGR
Salesman 7698
08-FEB-01
30
7900 James
Clerk
7698
03-DEC-01
9500
30
7521 Ward
Salesman 7698
22-FEB-01
12500
5000
HIREDATE
SAL
COMM
30
EMPNO ENAME
JOB
MGR
Analyst 7566
03-DEC-01
30000
7369 Smith
Clerk
7788 Scott
7902
17-DEC-00
8000
Analyst 7566
09-DEC-02
30000
20
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
Clerk
7788
12-JAN-03
11000
20
7934 Miller
Clerk
7782
23-JAN-02
13000
14 rows selected.
Q4.
ANS:
JOB
--------Manager
Clerk
COMM
Analyst
President
Salesman
Q5.
ANS:
JOB
--------President
Manager
Manager
Manager
Salesman
Salesman
Salesman
Clerk
Salesman
Analyst
Clerk
JOB
--------Analyst
Clerk
Clerk
14 rows selected.
Q6.
WAQ to display the Names, Numbers and Salaries added with their
commissions from Employees Table
ANS:
Names
Numbers Salary+Commission
7839
50000
Blake
7698
28500
Clark
7782
24500
Jones
7566
29750
Martin
7654
26500
Allen
7499
19000
Turner
7844
15000
James
7900
9500
Ward
7521
17500
Ford
7902
Smith
7369
Names
30000
8000
Numbers Salary+Commission
7788
Adams
Miller
7876
7934
30000
11000
13000
14 rows selected.
Q7.
ANS:
Null?
Type
EMPNO
ENAME
JOB
VARCHAR2(10)
NOT NULL VARCHAR2(9)
MGR
VARCHAR2(9)
HIREDATE
SAL
DATE
NUMBER(7,2)
COMM
NUMBER(7,2)
DEPTNO
NUMBER(2)
Null?
Type
DEPTNO
DNAME
LOC
VARCHAR2(15)
VARCHAR2(15)
Null?
Type
GRADE
NUMBER(1)
LOSAL
NUMBER(7,2)
HISAL
NUMBER(7,2)
Q8.
ANS:
50000
57500
Blake
28500
32775
Clark
24500
28175
Jones
29750
34212.5
Martin
12500
14375
Allen
16000
18400
Turner
15000
17250
James
9500
10925
Ward
12500
14375
Ford
Smith
30000
34500
8000
9200
30000
Adams
Miller
11000
13000
34500
12650
14950
14 rows selected.
Q9.
WAQ to display the annual salary of Employees with their names and
numbers
ANS:
600000
7698 Blake
342000
7782 Clark
294000
7566 Jones
357000
7654 Martin
150000
7499 Allen
192000
7844 Turner
180000
7900 James
114000
7521 Ward
150000
7902 Ford
7369 Smith
360000
96000
360000
132000
156000
14 rows selected.
Q10. WAQ to display the details of the employees and default values
(In place of Null values of commission use nvl function to show 0 )
ANS:
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
President
17-NOV-01
50000
10
7698 Blake
Manager 7839
01-MAY-01
28500
Manager 7839
09-JUN-01
24500
30
7782 Clark
10
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
Manager 7839
02-APR-01
29750
20
7654 Martin
Salesman 7698
28-SEP-01
12500
14000
30
7499 Allen
30
Salesman 7698
20-FEB-01
16000
3000
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
15000
Salesman 7698
08-FEB-01
30
7900 James
Clerk
7698
03-DEC-01
9500
30
7521 Ward
Salesman 7698
22-FEB-01
12500
5000
HIREDATE
SAL
COMM
30
EMPNO ENAME
JOB
MGR
7369 Smith
7788 Scott
Analyst 7566
03-DEC-01
30000
7902
17-DEC-00
8000
Analyst 7566
09-DEC-02
30000
Clerk
20
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
7876 Adams
Clerk
7788
12-JAN-03
11000
20
7934 Miller
Clerk
7782
23-JAN-02
13000
14 rows selected.
EMPLOYEE DETAILS
--------------------------------------------------------------------------------
EMPLOYEE DETAILS
--------------------------------------------------------------------------------
14 rows selected.
Q12. WAQ to display the ename joined with the Job using || operator
ANS:
Scott Analyst
Adams Clerk
Miller Clerk
14 rows selected.
ENAME
---------King
Blake
Clark
Jones
Allen
Turner
Ford
Scott
8 rows selected.
Q14. Give a query to display the names of employees who are not Managers
ANS:
ENAME
---------King
Martin
Allen
Turner
James
Ward
Ford
Smith
Scott
Adams
Miller
11 rows selected.
Q15. WAQ to display the names of Employees who are managers or analysts or
clerk using IN operator
ANS:
ENAME
---------Blake
Clark
Jones
James
Ford
Smith
Scott
Adams
Miller
9 rows selected.
Q16. WAQ to display the names of employees who didnt get any commission
ANS:
ENAME
---------King
Blake
Clark
Jones
James
Ford
Smith
Scott
Adams
Miller
10 rows selected.
Q17. WAQ to display the names, salaries and commission of employees who
dont
get commission
ANS:
ENAME
SAL
COMM
50000
Blake
28500
Clark
24500
Jones
29750
9500
30000
8000
30000
James
Ford
Smith
Scott
Adams
Miller
11000
13000
10 rows selected.
Q18. Select the names of employees whose salary is between 15000 and 20000
ANS:
ENAME
SAL
COMM
16000
15000
3000
0
Q19. WAQ to display the names of employees with their department names
ANS:
ENAME
DNAME
---------- --------------King
Accounting
Blake
Sales
Clark
Accounting
Jones
Research
Martin
Sales
Allen
Sales
Turner
Sales
James
Sales
Ward
Sales
Scott
Research
Adams
Research
11 rows selected.
Q20. WAQ to display the names of employees with their salary grades
ANS:
ENAME
GRADE
---------- ---------Smith
James
Adams
Ward
Martin
Miller
Turner
Allen
Clark
Blake
Jones
ENAME
GRADE
---------- ---------Ford
Scott
King
14 rows selected.
ENAME
---------Smith
Scott
no rows selected
Q23. Display the names of employees whose name holds the character O in
any place
ANS:
no rows selected
Q24. WAQ to display the names of employees in the order of their salary
ascending and descending separately
ANS:
ENAME
SAL
---------- ---------Smith
8000
James
9500
Adams
11000
Ward
12500
Martin
12500
Miller
Turner
13000
15000
Allen
16000
Clark
24500
Blake
28500
Jones
29750
ENAME
SAL
---------- ---------Ford
30000
Scott
30000
King
50000
14 rows selected.
ENAME
SAL
---------- ---------King
50000
Scott
30000
Ford
30000
Jones
29750
Blake
28500
Clark
24500
Allen
16000
Turner
Miller
15000
13000
Ward
12500
Martin
12500
ENAME
SAL
---------- ---------Adams
11000
James
9500
Smith
8000
14 rows selected.
Q25. Give a query to display the names of employees whose name has
only four characters
ANS:
ENAME
---------King
Ward
Ford
Q26. WAQ to display the name, job, salary and hiredate of employees where
salary is between 10000 and 20000 in ascending order of their hiredate
ANS:
ENAME
JOB
SAL HIREDATE
Salesman
Salesman
Salesman
15000 08-FEB-01
16000 20-FEB-01
12500 22-FEB-01
Martin
Salesman
Miller
Clerk
Adams
Clerk
12500 28-SEP-01
13000 23-JAN-02
11000 12-JAN-03
6 rows selected.
Q27. WAQ to display the names of employees concatenated with their job and
use alias by NameJob and sort them using the alias name in
descending order
ANS:
NameJob
------------------WardSalesman
TurnerSalesman
SmithClerk
ScottAnalyst
MillerClerk
MartinSalesman
KingPresident
JonesManager
JamesClerk
FordAnalyst
ClarkManager
NameJob
------------------BlakeManager
AllenSalesman
AdamsClerk
14 rows selected.
Q28. Display the names, number, job, salary of employees who do not have
manager
ANS:
ENAME
EMPNO JOB
SAL
7839 President
50000
4*5+6/2
---------23
Date
--------05-APR-10
Sum
---------- ---------- ---------- ---------- ------------- ---------- ---------290250 20732.1429 129843431 11394.8862
14
8000
50000
JOB
Min Sal
Max Sal
24500
Clerk
8000
Analyst
30000
President
Salesman
29750
13000
50000
12500
30000
50000
16000
DEPTNO No of Emploees
---------- -------------10
20
30
Q35. Display the no. of employees job wise within department wise
ANS:
DEPTNO JOB
COUNT(EMPNO)
10 President
20 Analyst
20 Clerk
1
1
1
20 Manager
30 Clerk
1
1
30 Manager
30 Salesman
8 rows selected.
DEPTNO
Manager
---------- ---------10
20
30
Q37. Display the names of departments which consist more than 4 employees
ANS:
DNAME
--------------Sales
Q38. WAQ to display the department number and salary difference in each
department where department is not 40 and difference is > 5000 (show
in ascending order of the difference)
ANS:
19000
20
19000
10
25500
Q39. Show which positions are paid a higher than average salary
ANS:
ENAME
---------King
Blake
Clark
Jones
Ford
Scott
6 rows selected.
SAL
---------30000
SAL
---------12500
Q42. Select the name of employees who are getting minimum salary in
employee table
ANS:
ENAME
---------Smith
Q43. Select the names of employees who are getting maximum salary in each
department
ANS:
ENAME
---------King
Blake
Ford
Scott
Q44. Show details of those employees that have salary equal to any employees
of department
ANS:
SQL> select
E.EMPNO,E.ENAME,E.JOB,E.MGR,E.HIREDATE,E.COMM,E.SAL,E.DEPTNO
2 from EMPLOYEE E,EMPLOYEE D
3 where E.EMPNO!=D.EMPNO
4 and E.SAL=D.SAL and E.DEPTNO=D.DEPTNO;
EMPNO ENAME
JOB
MGR
HIREDATE
COMM
SAL
Salesman 7698
22-FEB-01
5000
12500
Salesman 7698
28-SEP-01
14000
12500
30
7654 Martin
30
Q45. Show details of those employee that have salary more than or equal to
average salary
ANS:
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
---------7839 King
President
17-NOV-01
50000
10
7698 Blake
Manager 7839
01-MAY-01
28500
Manager 7839
09-JUN-01
24500
30
7782 Clark
10
EMPNO ENAME
JOB
MGR
HIREDATE
SAL
COMM
Manager 7839
02-APR-01
29750
20
7902 Ford
Analyst 7566
03-DEC-01
30000
7788 Scott
Analyst 7566
09-DEC-02
30000
20
6 rows selected.
Q46. Select the details of departments that have at least one employee
ANS:
DEPTNO DNAME
LOC
New Delhi
Chennai
Bombay