SlideShare a Scribd company logo
1 of 9
Download to read offline
Sample Table – Worker
WORKER_IDFIRST_NAMELAST_NAME SALARY JOINING_DATE DEPARTMENT
001 Monika Arora 100000 2014-02-20 09:00:00 HR
002 Niharika Verma 80000 2014-06-11 09:00:00 Admin
003 Vishal Singhal 300000 2014-02-20 09:00:00 HR
004 Amitabh Singh 500000 2014-02-20 09:00:00 Admin
005 Vivek Bhati 500000 2014-06-11 09:00:00 Admin
006 Vipul Diwan 200000 2014-06-11 09:00:00 Account
007 Satish Kumar 75000 2014-01-20 09:00:00 Account
008 Geetika Chauhan 90000 2014-04-11 09:00:00 Admin
Sample Table – Bonus
WORKER_REF_ID BONUS_DATE BONUS_AMOUNT
1 2016-02-20
00:00:00
5000
2 2016-06-11
00:00:00
3000
3 2016-02-20
00:00:00
4000
1 2016-02-20
00:00:00
4500
2 2016-06-11
00:00:00
3500
Sample Table – Title
WORKER_REF_ID WORKER_TITLE AFFECTED_FROM
1 Manager 2016-02-20 00:00:00
2 Executive 2016-06-11 00:00:00
8 Executive 2016-06-11 00:00:00
5 Manager 2016-06-11 00:00:00
4 Asst. Manager 2016-06-11 00:00:00
7 Executive 2016-06-11 00:00:00
6 Lead 2016-06-11 00:00:00
3 Lead 2016-06-11 00:00:00
Perform Following Task
1. Create Tables and Insert data (First data using Insert query rest can be feeded.)
2. Write an SQL query to print details of the Workers whose FIRST_NAME ends with
‘h’ and contains six alphabets.
3. Change Last_Name Columns name to Surname.
4. Write an SQL query to print details of the Workers whose SALARY lies between
100000 and 500000.
5. Write an SQL query to fetch the count of employees working in the department
‘Admin’.
6. Write an SQL query to fetch the no. of workers for each department in the
descending order.
7. Write an SQL query to print details of the Workers who are also Managers.
8. Select Top 10 salaries and Employees Full name from Worker table.
9. Write an SQL query to fetch the list of employees with the same salary.
Question-1. Create Tables and Insert data (First data using Insert query rest can be
feeded.)
Answer 1.
CREATE TABLE WORKER(
WORKER_ID NUMBER(4),
FIRST_NAME VARCHAR2(10),
LAST_NAME VARCHAR2(10),
SALARY NUMBER(10),
JOINING_DATE TIMESTAMP ,
DEPARTMENT VARCHAR2(10));
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Monika','Arora',100000,TIMESTAMP '2014-02-20
09:00:00','HR');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Niharika','Verma',80000,TIMESTAMP '2014-06-11
09:00:00','Admin');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Vishal','Singhal',300000,TIMESTAMP '2014-02-20
09:00:00','HR');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Amitabh','Singh',500000,TIMESTAMP '2014-02-20
09:00:00','Admin');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Vivek','Bhati',500000,TIMESTAMP '2014-06-11
09:00:00','Admin');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Vipul','Diwan',200000,TIMESTAMP '2014-06-11
09:00:00','Acount');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Satish','Kumar',75000,TIMESTAMP '2014-01-20
09:00:00','Acount');
insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
values(worker_seq.nextval,'Geetika','Chauhan',90000,TIMESTAMP '2014-04-11
09:00:00','Admin');
Question-2:- Write an SQL query to print details of the Workers whose FIRST_NAME
ends with ‘h’ and contains six alphabets.
Answer-2:-
Select * from Worker where FIRST_NAME like '_____h';
Question-3:- Change Last_Name Columns name to Surname.
Answer-3:- ALTER TABLE Worker RENAME COLUMN Last_name TO Surname;
Question-4:-. Write an SQL query to print details of the Workers whose SALARY lies
between 100000 and 500000.
Answer-4:- select * from worker where salary between 100000 and 500000;
Queston-5:- Write an SQL query to fetch the count of employees working in the department
‘Admin’.
Answer-5:-
select count (*) from worker where department ='Admin';
Question-6:- Write an SQL query to fetch the no. of workers for each department in the
descending order
Answer-6:-
SELECT DEPARTMENT, count(WORKER_ID) No_Of_Workers
FROM worker
GROUP BY DEPARTMENT
ORDER BY No_Of_Workers DESC;
Question-7:- Write an SQL query to print details of the Workers who are also Managers.
Answer-7:-
SELECT DISTINCT W.FIRST_NAME, T.WORKER_TITLE
FROM Worker W
INNER JOIN Title T
ON W.WORKER_ID = T.WORKER_REF_ID
AND T.WORKER_TITLE in ('Manager');
Question-8:- Select Top 10 salaries and Employees Full name from Worker table.
Answer-8:-
SELECT * FROM (SELECT * FROM Worker ORDER BY Salary
DESC)
WHERE ROW NUM <= 10;
Question-9:- Write an SQL query to fetch the list of employees with the same salary.
Answer-9:-
Select distinct W.WORKER_ID, W.FIRST_NAME, W.Salary
from Worker W, Worker W1
where W.Salary = W1.Salary
and W.WORKER_ID != W1.WORKER_ID;
Important dbms practical  question

More Related Content

More from TEJVEER SINGH

Most Important C language program
Most Important C language programMost Important C language program
Most Important C language program
TEJVEER SINGH
 
Multi Banking System
Multi Banking SystemMulti Banking System
Multi Banking System
TEJVEER SINGH
 

More from TEJVEER SINGH (10)

HOW TO DOWNLOAD MICROSOFT WORD IN ANDROID, and How to convert doc file into ...
HOW TO DOWNLOAD MICROSOFT WORD  IN ANDROID, and How to convert doc file into ...HOW TO DOWNLOAD MICROSOFT WORD  IN ANDROID, and How to convert doc file into ...
HOW TO DOWNLOAD MICROSOFT WORD IN ANDROID, and How to convert doc file into ...
 
Computer graphics unit 4th
Computer graphics unit 4thComputer graphics unit 4th
Computer graphics unit 4th
 
Most Important C language program
Most Important C language programMost Important C language program
Most Important C language program
 
Multi Banking System
Multi Banking SystemMulti Banking System
Multi Banking System
 
Design principle of pattern recognition system and STATISTICAL PATTERN RECOGN...
Design principle of pattern recognition system and STATISTICAL PATTERN RECOGN...Design principle of pattern recognition system and STATISTICAL PATTERN RECOGN...
Design principle of pattern recognition system and STATISTICAL PATTERN RECOGN...
 
Computer network questions
Computer network questionsComputer network questions
Computer network questions
 
#How to install mongoDB and also setup path
#How to install mongoDB and also setup path#How to install mongoDB and also setup path
#How to install mongoDB and also setup path
 
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracaleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracaleDriverjava.lang.ClassNotFoundException: oracle.jdbc.driver.OracaleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracaleDriver
 
Oracle 10g Installation Guide
Oracle 10g Installation GuideOracle 10g Installation Guide
Oracle 10g Installation Guide
 
Shift reduce parser
Shift reduce parserShift reduce parser
Shift reduce parser
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Recently uploaded (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 

Important dbms practical question

  • 1. Sample Table – Worker WORKER_IDFIRST_NAMELAST_NAME SALARY JOINING_DATE DEPARTMENT 001 Monika Arora 100000 2014-02-20 09:00:00 HR 002 Niharika Verma 80000 2014-06-11 09:00:00 Admin 003 Vishal Singhal 300000 2014-02-20 09:00:00 HR 004 Amitabh Singh 500000 2014-02-20 09:00:00 Admin 005 Vivek Bhati 500000 2014-06-11 09:00:00 Admin 006 Vipul Diwan 200000 2014-06-11 09:00:00 Account 007 Satish Kumar 75000 2014-01-20 09:00:00 Account 008 Geetika Chauhan 90000 2014-04-11 09:00:00 Admin Sample Table – Bonus WORKER_REF_ID BONUS_DATE BONUS_AMOUNT 1 2016-02-20 00:00:00 5000 2 2016-06-11 00:00:00 3000 3 2016-02-20 00:00:00 4000 1 2016-02-20 00:00:00 4500 2 2016-06-11 00:00:00 3500 Sample Table – Title WORKER_REF_ID WORKER_TITLE AFFECTED_FROM 1 Manager 2016-02-20 00:00:00 2 Executive 2016-06-11 00:00:00 8 Executive 2016-06-11 00:00:00 5 Manager 2016-06-11 00:00:00 4 Asst. Manager 2016-06-11 00:00:00 7 Executive 2016-06-11 00:00:00 6 Lead 2016-06-11 00:00:00 3 Lead 2016-06-11 00:00:00
  • 2. Perform Following Task 1. Create Tables and Insert data (First data using Insert query rest can be feeded.) 2. Write an SQL query to print details of the Workers whose FIRST_NAME ends with ‘h’ and contains six alphabets. 3. Change Last_Name Columns name to Surname. 4. Write an SQL query to print details of the Workers whose SALARY lies between 100000 and 500000. 5. Write an SQL query to fetch the count of employees working in the department ‘Admin’. 6. Write an SQL query to fetch the no. of workers for each department in the descending order. 7. Write an SQL query to print details of the Workers who are also Managers. 8. Select Top 10 salaries and Employees Full name from Worker table. 9. Write an SQL query to fetch the list of employees with the same salary. Question-1. Create Tables and Insert data (First data using Insert query rest can be feeded.) Answer 1. CREATE TABLE WORKER( WORKER_ID NUMBER(4), FIRST_NAME VARCHAR2(10), LAST_NAME VARCHAR2(10), SALARY NUMBER(10), JOINING_DATE TIMESTAMP , DEPARTMENT VARCHAR2(10)); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Monika','Arora',100000,TIMESTAMP '2014-02-20 09:00:00','HR'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Niharika','Verma',80000,TIMESTAMP '2014-06-11 09:00:00','Admin'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Vishal','Singhal',300000,TIMESTAMP '2014-02-20 09:00:00','HR'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Amitabh','Singh',500000,TIMESTAMP '2014-02-20 09:00:00','Admin'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department)
  • 3. values(worker_seq.nextval,'Vivek','Bhati',500000,TIMESTAMP '2014-06-11 09:00:00','Admin'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Vipul','Diwan',200000,TIMESTAMP '2014-06-11 09:00:00','Acount'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Satish','Kumar',75000,TIMESTAMP '2014-01-20 09:00:00','Acount'); insert into worker(Worker_id,first_name,last_name,salary,joining_date,department) values(worker_seq.nextval,'Geetika','Chauhan',90000,TIMESTAMP '2014-04-11 09:00:00','Admin'); Question-2:- Write an SQL query to print details of the Workers whose FIRST_NAME ends with ‘h’ and contains six alphabets. Answer-2:- Select * from Worker where FIRST_NAME like '_____h';
  • 4. Question-3:- Change Last_Name Columns name to Surname. Answer-3:- ALTER TABLE Worker RENAME COLUMN Last_name TO Surname;
  • 5. Question-4:-. Write an SQL query to print details of the Workers whose SALARY lies between 100000 and 500000. Answer-4:- select * from worker where salary between 100000 and 500000; Queston-5:- Write an SQL query to fetch the count of employees working in the department ‘Admin’. Answer-5:- select count (*) from worker where department ='Admin';
  • 6. Question-6:- Write an SQL query to fetch the no. of workers for each department in the descending order Answer-6:- SELECT DEPARTMENT, count(WORKER_ID) No_Of_Workers FROM worker GROUP BY DEPARTMENT ORDER BY No_Of_Workers DESC;
  • 7. Question-7:- Write an SQL query to print details of the Workers who are also Managers. Answer-7:- SELECT DISTINCT W.FIRST_NAME, T.WORKER_TITLE FROM Worker W INNER JOIN Title T ON W.WORKER_ID = T.WORKER_REF_ID AND T.WORKER_TITLE in ('Manager'); Question-8:- Select Top 10 salaries and Employees Full name from Worker table. Answer-8:- SELECT * FROM (SELECT * FROM Worker ORDER BY Salary DESC) WHERE ROW NUM <= 10;
  • 8. Question-9:- Write an SQL query to fetch the list of employees with the same salary. Answer-9:- Select distinct W.WORKER_ID, W.FIRST_NAME, W.Salary from Worker W, Worker W1 where W.Salary = W1.Salary and W.WORKER_ID != W1.WORKER_ID;