Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
530 views

SQL Imp Ques

The document contains questions related to SQL queries on various tables. It asks to write SQL commands to retrieve specific data from the tables based on given conditions and provides the structure of tables on which the queries need to be executed. It also asks for output of some sample queries on the tables.

Uploaded by

Tanya Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
530 views

SQL Imp Ques

The document contains questions related to SQL queries on various tables. It asks to write SQL commands to retrieve specific data from the tables based on given conditions and provides the structure of tables on which the queries need to be executed. It also asks for output of some sample queries on the tables.

Uploaded by

Tanya Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

6 Marks Questions

SQL
1.

Write SQL commands for (a) to ( j) and write output for (h) on the basis of Teacher relation given
below.
No
1.
2.
3.
4.
5.
6.
7.
8.
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
k)

2.

Name
Jigal
Sharmila
Sandeep
Sangeeta
Rakesh
Shyam
Shiv Om
Shalakha

Age
34
31
32
35
42
50
44
33

Department
Computer
History
Maths
History
Maths
History
Computer
Maths

Date of Join
10/01/97
24/03/98
12/12/96
01/07/99
05/09/97
27/02/97
25/02/97
31/07/97

Salary
12000
20000
30000
40000
25000
30000
21000
20000

Sex
M
F
M
F
M
M
M
F

To show all information about the teacher of history department.


To list the names of female teachers who are in Maths department
To list names of all teachers with their date of joining in ascending order.
To display students name, fee,age for male teacher only
To count the number of teachers with age>23.
To insert a new row in the TEACHER table with the following data:
9,Raja,26,Computer,13/05/95,2300,M.
To show all information about the teachers in this table
Add a new column named Address.
Arrange the whole table in the alphabetical order to name
Display the age of the teachers whose name starts with S,.
Give the output of following statement.
(j) Select COUNT(distinct department) from TEACHER.
(ii)
Select MAX(Age)from Teacher where sex=F
(iii)
Select AVG(Salary) from Teacher where Dateofjoin<12/07/96
(iv)
Select SUM(Salary) from teacher where Dateofjoin<12/07/96

TABLE : EMP
EMPNO ENAME
7839
REA
1234
PREM
6754
SITA
6574
GITA
9876
HONEY
8976
REEMA

JOB
MANAGER
CLERK
MANAGER
SALESMAN
CLERK
SALESMAN

MGR
67
87
89
98
65
91

HIREDATE SAL
12-DEC-98
5000
11-FEB-77
12000
12-MAR-99 10000
11-JUN-99
9000
12-JUN-00
12000
10-SEP-88
6000

COMM DEPTNO
0
10
1500
20
1000
20
0
30
800
20
100
30

(a) Display names of employees whose names include either of the substring TH or LL.
(b) Display data of all employees sorted by their department, seniority and salary.
(c) Find all the employees who have no manager.
(d) To display all employees who were hired during 1995.
(e) Show the average salary for all departments with more than 3 people for a job.
P a g e | 71

3.

(f) Find out number of employees having MANAGER as job.


(g) Create view DEPT20 with name and the salary of employees for dept 20.
(h) Display department no. and number of employees in each department.
(i) Find the output of the following :
1. SELECT SYSDATE FROM DUAL;
2. SELECT ENAME,SAL FROM EMPLOYEE WHERE DEPTNO=20;
3. SELECT COUNT(*) FROM EMP;
4. SELECT AVG(SAL) FROM EMP;
Consider the following WORKERS and DESIG. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii)
WORKERS
W_ID
102
105
144

FIRSTNAME
Sam
Sarah
Manila

LASTNAME
Tones
Ackerman
Sengupta

210

George

Smith

255

Mary

Jones

300
335

Robert
Henry

Samuel
Williams

403

Ronny

Lee

451

Pat

Thompson

ADDRESS
33 Elm St.
440 U.S. 110
24 Friends
Street
83
First
Street
842
Vine
Ave.
9 Fifth Cross
12Moore
Street
121 Harrison
St.
11 Red Road

CITY
Paris
New York
New Delhi
Howard
Losantiville
Wasington
Boston
New York
Paris

DESIG
W_ID
SALARY
BENEFITS
DESIGNATION
102
75000
15000
Manager
105
85000
25000
Director
144
70000
15000
Manager
210
75000
12500
Manager
255
50000
12000
Clerk
300
45000
10000
Clerk
335
40000
10000
Clerk
400
32000
7500
Salesman
451
28000
7500
Salesman
(i)
To display W_ID, FIRSTNAME, ADDRESS and CITY of all employees living in NEW
YORK from the table WORKERS.
(ii)
To display the content of workers table in ascending order of LASTNAME.
(iii)
To display the FIRSTNAME, LASTNAME and total salary of all alerks from the
tables WORKERS and DESIGN, where total salary is calculated as SALARY +
BENEFITS.
(iv)
To display the minimum salary among Managers and Clerks from the table DESIG.
(v)
Give the output of following:
a. SELECT FIRSTNAME, SALARY FROM WORKERS, DESIG WHERE
P a g e | 72

4.

DESIGNATION = Manager AND WORKERS.W_ID = DESIG.W_ID


b. SELECT COUNT(DISTINCT DESIGNATION) FROM DESIG.
c. SELECT DESIGNATION, SUM(SALARY FROM DESIGNATION GROUP BY
DESIGNATION HAVING COUNT(*)<3;
SELECT SUM(BENEFITS) FROM WORKERS WHERE DESIGNATION = Salesman;
Write SQL commands for the statements (i) to (vi) on the basis of the table EMPLOYEE:
Name
G. Hussain
Pallav
Y.D.
Sharma
Bhawna
A. Dasgupta
P. Arora
Col. Singhvi
Amit
A Dsouza

5.

EmpNo
2098
3099
8001
7901
5400
3400
2100
3100
2211

DeptNo
10
30
20
10
20
10
30
30
10

Job
President
Manager
Clerk

Sal
7000
9000
8500

President
Analyst
Clerk
Manager
Analyst
Clerk

4520
6580
12000
1200
3250
6900

Comm
1400

300

500

i.
Show sum and average salary for marketing deptt.
ii.
Check all employees have unique names.
iii.
Find al employess whose deptt is same as of Amit.
iv.
Increase the salary of all employees by 10%,
v.
Find the deptt that is paying max salaries to its employees.
vi.
Display the details of all the employees having salary less than 10000.
Write the SQL commands for (a) to (d) and write the output for (e) on
the basis of table Hospital :
No
1
2
3
4
5
6
7
8
9
10
(a)
(b)
(c)
(d)
(e)
(i)

Name
Arpit
Zayana
Kareem
Abhilash
Dhanya
Siju
Ankita
Divya
Nidhin
Hari

Age
62
18
22
26
24
23
16
15
25
28

Department
Surgery
ENT
Orthopedic
Surgery
ENT
Cardiology
ENT
Cardiology
Orthopedic
Surgery

Dateofadmin
21/01/06
12/12/05
19/02/06
24/11/06
20/10/06
10/10/06
13/04/06
10/11/06
12/05/06
19/03/06

Charge
300
250
450
300
350
800
100
500
700
450

To show all information about the patients of cardiology department.


To list the name of female patients who are in ENT department.
To list names of all patients with their date of admission in ascending
order.
To count the no of patients with age > 20.
Give the output of the following SQL commands:
Select COUNT(DISTINCT charges ) from hospital;
P a g e | 73

Sex
M
F
M
M
F
M
F
F
M
M

6.

(ii)
Select MIN(age) from hospital where Sex=M;
(iii)
Select SUM(charges) from hospital where Sex =F;
(iv)
Select avg(charges) from hospital where dateofadm>{12/05/06};
Write the SQL commands for the following on the basis of tables INTERIORS and NEWONES
Table:
INTERORS
SNO ITEMNAME
TYPE
1
Red Rose
Double Bed
2
Soft Touch
Baby Cot
3
Jerrys Home
Baby Cot
4
Rough Wood
Office Table
5
Comfort Zone Double Bed
6
Jerry Look
Baby Cot
7
Lion King
Office Table
8
Royal Tiger
Sofa
9
Park Sitting
Sofa
10
Dine Paradise Dining Table
Table: NEWONES
SNO
ITEMNAME
TYPE

7.

11

White Wood

12

James 007

Double
Bed
Sofa

13

Tom Look

Baby Cot

DATEOFSTOCK
23/02/02
20/1//02
19/02/02
01/01/02
12/01/02
24/02/02
20/02/02
22/02/02
13/12/01
19/02/02

PRICE DISCOUNT
32000
15
9000
10
8500
10
20000
20
15000
20
7000
19
16000
20
30000
25
9000
15
11000
15

DATEOFSTOCK

PRICE

DISCOUNT

23/02/02

20000

20

20/02/03

15000

15

21/02/03

7000

10

(i)
To list the ITEMNAME which are priced at more than 1000 from the INTERIORS
table
(ii)
To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before
22/01/02 from the INTERIORS table in descending order of ITEMNAME
(iii)
To show all information about the sofas from the INTERIORS table
(iv)
To display ITEMNAME and DATEOF STOCK of those items in which the discount
percentage is more than 15 from INTERIORS table
(v)
To count the number of items, whose type is Double Bed from INTERIORS table
(vi)
To insert a new row in the NEWONES table with the following data
14,True Indian, Office Table, 28/03/03,15000,20
c)
Get the Output (Use the above table without inserting the record)
Select COUNT(distinct TYPE) from INTERIORS
Select AVE(DISCOUNT) from INTERIORS where TYPE=Baby Cot
Select SUM(Price) from INTERIORS where DATEOF STOCK<{12/02/02}
Select MAX(Price) from INTERIORS , NEWONES;
Given the following tables for a database FURNITURE :
Note:
Write SQL
command for (a) to (d) and write the outputs for (e) on the basis of tables FURNITURE and
ARRIVALS.

P a g e | 74

NO.
1
2
3
4
5.
6
7
8
9
10
NO.
11
12
13

Table: FURNITURE
ITEMNAME TYPE
DATEOFSTOCK
White lotus
Double Bed
23/02/02
Pink teather
Baby cot
20/01/02
Dolphin
Baby cot
19/02/02
Office
Decent
01/01/02
Table
Comfort zone Double Bed 12/01/02
Donald
Baby cot
24/02/02
Office
Royal Finish
20/02/02
Table
Royal tiger
Sofa
22/02/02
Econo sitting Sofa
13/12/01
Eating
Dining
19/02/02
Paradise
Table
Table : ARRIVALS
ITEMNAME
TYPE
DATEOFSTOCK
Wood Comfort Double Bed 23/03/03
Old Fox
Sofa
20/02/03
Micky
Baby cot
21/02/03

PRICE
30000
7000
9500

DISCOUNT
25
20
20

25000

30

25000
6500

25
15

18000

30

31000
9500

30
25

11500

25

PRICE DISCOUNT .
25000
25
17000
20
7500
15

(a). To list the ITEMNAME which are priced at more than 15000 from the
FURNITURE table.
(b) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before
22/01/02 from the FURNITURE table in descending order of ITEMNAME.
(c) To display ITEMNAME and DATEOFSTOCK of those items, in which the DISCOUNT percentage is more than 25 from FURNITURE table.
(d) To count the number of items, whose TYPE is Sofa from FURNITURE table.
(e) Give the output of fol1owing SQL statement:
Note: Outputs of the below mentioned queries should be based on original data given
in both the tables .
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE, ARRIVALS;
(iil) Select AVG(DISCOUNT) from FURNITURE where TYPE = Baby cot ;
(iv) Select SUM(PRICE) from FURNITURE where DATEOFSTOCK <
{12/02/02}
8.

Given the following LAB table, write SQL command for the questions
give the output of (iv).

6
P a g e | 75

(i) to (iii) and

9.

LAB
No ItemName CostPerItem Quantity Dateofpurchase Warranty Operational
1
Computer 60000
9
21/5/96
2
7
2
Printer
15000
3
21/5/97
4
2
3
Scanner
18000
1
29/8/98
3
1
4
Camera
21000
2
13/10/96
1
1
5
Switch
8000
1
31/10/99
2
1
6
UPS
5000
5
21/5/96
1
4
7
Router
25000
2
11/1/2000
2
5
(i)
To select the ItemName,which are within the Warranty period till
present date.
(ii) To display all the itemName whose name starts with C.
(iii) To list the ItemName in ascending order of the date of purchase Where quantity is more
than 3.
(iv) Give the output of the following SQL commands:
(a) select min(DISTINCT Quantity) from LAB;
(b) select max(Warranty) from LAB;
(C) select sum(CostPerItem) from Lab;
Table : SchoolBus
Rtno Area_overed
Capacity No
of Distance
Transporter
Charges
students
1
Vasant kunj
100
120
10
Shivamtravels 100000
2
Hauz Khas
80
80
10
Anand travels 85000
3
Pitampura
60
55
30
Anand travels 60000
4
Rohini
100
90
35
Anand travels 100000
5
Yamuna
50
60
20
Bhalla Co.
55000
Vihar
6
Krishna
70
80
30
Yadav Co.
80000
Nagar
7
Vasundhara
100
110
20
Yadav Co.
100000
8
Paschim
40
40
20
Speed travels 55000
Vihar
9
Saket
120
120
10
Speed travels 100000
10
Jank Puri
100
100
20
Kisan Tours
95000
(a) To show all information of students where capacity is more than the no of student in order
of rtno.
(b) To show area_covered for buses covering more than 20 km., but charges less then 80000.
(c) To show transporter wise total no. of students traveling.
(d) To show rtno, area_covered and average cost per student for all routes where average cost
per student is - charges/noofstudents.
(e) Add a new record with following data:
(11, Moti bagh,35,32,10, kisan tours , 35000)
(f)
Give the output considering the original relation as given:
(i) select sum(distance) from schoolbus where transporter= Yadav travels;
(ii) select min(noofstudents) from schoolbus;
(iii) select avg(charges) from schoolbus where transporter= Anand travels;
(v) select distinct transporter from schoolbus;
(vi)
P a g e | 76

10

TABLE : GRADUATE
S.NO
1
2
3
4
5
6
7
8
9
10

NAME
KARAN
DIWAKAR
DIVYA
REKHA
ARJUN
SABINA
JOHN
ROBERT
RUBINA
VIKAS

STIPEND
400
450
300
350
500
400
250
450
500
400

SUBJECT
PHYSICS
COMP. Sc.
CHEMISTRY
PHYSICS
MATHS
CEHMISTRY
PHYSICS
MATHS
COMP. Sc.
MATHS

AVERAGE
68
68
62
63
70
55
64
68
62
57

DIV.
I
I
I
I
I
II
I
I
I
II

(a)
(b)

List the names of those students who have obtained DIV 1 sorted by NAME.
Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend
received in a year assuming that the STIPEND is paid every month.
(c) To count the number of students who are either PHYSICS or COMPUTER SC
graduates.
(d) To insert a new row in the GRADUATE table:
11,KAJOL, 300, computer sc, 75, 1
(e) Give the output of following sql statement based on table GRADUATE:
i. Select MIN(AVERAGE) from GRADUATE where SUBJECT=PHYSICS;
ii. Select SUM(STIPEND) from GRADUATE WHERE div=2;
iii. Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
iv. Select COUNT(distinct SUBDJECT) from GRADUATE;
Assume that there is one more table GUIDE in the database as shown below:
Table: GUIDE
MAINAREA
PHYSICS
COMPUTER SC
CHEMISTRY
MATHEMATICS

ADVISOR
VINOD
ALOK
RAJAN
MAHESH

g) What will be the output of the following query:


SELECT NAME, ADVISOR FROM GRADUATE,GUIDE WHERE SUBJECT=
MAINAREA;

P a g e | 77

11.

Write SQL command for (a) to (g) on the basis of the table SPORTS
Student
NO
10
11
12
13
14
15
(a)
(b)
(c)
(d)
(e)
(f)
(g)

12.

Class

Name

Game1

Grade

Game2

Grade2

7
8
7
7
9
10

Sammer
Sujit
Kamal
Venna
Archana
Arpit

Cricket
Tennis
Swimming
Tennis
Basketball
Cricket

B
A
B
C
A
A

Swimming
Skating
Football
Tennis
Cricket
Atheletics

A
C
B
A
A
C

Display the names of the students who have grade C in either Game1 or Game2
or both.
Display the number of students getting grade A in Cricket.
Display the names of the students who have same game for both Game1 and
Game2.
Display the games taken up by the students, whose name starts with A.
Assign a value 200 for Marks for all those who are getting grade B or grade A
n both Game1 and Game2.
Arrange the whole table in the alphabetical order of Name.
Add a new column named Marks.
Employees
Empid
010
105
152
215
244
300
335
400
441

Firstname
Ravi
Harry
Sam
Sarah
Manila
Robert
Ritu
Rachel
Peter

Lastname
Kumar
Waltor
Tones
Ackerman
Sengupta
Samuel
Tondon
Lee
Thompson

Address
Raj nagar
Gandhi nagar
33 Elm St.
440 U.S. 110
24 Friends street
9 Fifth Cross
Shastri Nagar
121 Harrison St.
11 Red Road

City
GZB
GZB
Paris
Upton
New Delhi
Washington
GZB
New York
Paris

EmpSalary
Empid
010
105
152
215
244
300
335
400
441

Salary
75000
65000
80000
75000
50000
45000
40000
32000
28000

Benefits
15000
15000
25000
12500
12000
10000
10000
7500
7500
P a g e | 78

Designation
Manager
Manager
Director
Manager
Clerk
Clerk
Clerk
Salesman
salesman

Write the SQL commands for the following :


(i)
To show firstname,lastname,address and city of all employees living in paris
(ii)
To display the content of Employees table in descending order of Firstname.
(iii)
To display the firstname,lastname and total salary of all managers from the tables
Employee and empsalary , where total salary is calculated as salary+benefits.
(iv)
To display the maximum salary among managers and clerks from the table
Empsalary.
(v)
Give the Output of following SQL commands:
(i)
Select firstname,salary from employees ,empsalary where designation = Salesman
and Employees.empid=Empsalary.empid;
(ii)
Select count(distinct designation) from empsalary;
(iii)
Select designation, sum(salary) from empsalary group by designation having count(*)
>2;

13

(iv)
Select sum(benefits) from empsalary where designation =Clerk;
Write SQL commands for the following taking in view the following table as SCHOOL:
No.
1
2
3
4
5
6
7
8

14.

Name
Ankit
Sumit
Amit
Suchitra
Ankita
Shruti
Raksha
Priya

Age
45
32
22
23
22
21
22
33

Department
Comp.Sc.
History
Geog
Maths
Hindi
Comp.Sc.
Hindi
Maths

Sex
M
M
M
F
F
F
F
F

b. To show all information about the members of the Hindi Department.


c. To list the names of female members who are in Hindi department.
d. To list names of all members with the ascending order of their ages.
e. To display members name, age and department name of males.
f. To count the number of members with age >21.
g. To insert a new row in the SCHOOL table with the following data :
9, Pinto,31,Maths,M
h. Give the output of the following, considering the above table :
a. SELECT COUNT (DISTINCT AGE) FROM SCHOOL;
b. SELECT MAX(AGE) FROM SCHOOL WHERE SEX = M;
c. SELECT AVG(AGE) FROM SCHOOL WHERE SEX =M;
d. SELECT SUM(AGE) FROM SCHOOL WHERE SEX=M;
Write SQL command for (a) to (g) on the basis of the table GAMES
Table: GAMES
GCode
Game Name
Number
PrizeMoney
ScheduleDate
101
Carom Board
2
5000
23-Jan-2004
102
Badminton
2
12000
12-Dec-2003
103
Table Tennis
4
8000
14-Feb-2004
105
Chess
2
9000
01-Jan-2004
108
Lawn Tennis
4
25000
19-Mar-2004

P a g e | 79

Table: PLAYER
Pcode Name
GCode
1
Nabi Ahmed
101
2
Ravi Sahai
108
3
Jatin
101
4
Nazneen
103
(a) To Display the details of all games with their codes.
(b) To display details of those games which are having PrizeMoney more than 7000.
(c) To display the content of GAMES table in ascending order of ScheduleDate.
(d) TO Display sum of PrizeMoney for each of the number of participation grouping
(as shown in column number 3.
(e) SELECT COUNT (DISTINCT Number) FROM GAMES;
(f) SELECT MAX (ScheduleDate), MIN (ScheduleDate) FROM GAMES;
(g) SELEC SUM (PrizeMoney) FROM GAMES;
(h) SELECT DISTINCE Gcode FROM PLAYER;

P a g e | 80

You might also like