Beruflich Dokumente
Kultur Dokumente
Q3. Write SQL command for (i) to (vii) on the basis of the table SPORTS
Table: SPORTS
Student NO
10
11
12
13
14
15
Class
7
8
7
7
9
10
Name
Sammer
Sujit
Kamal
Venna
Archana
Arpit
Game1
Cricket
Tennis
Swimming
Tennis
Basketball
Cricket
Grade
B
A
B
C
A
A
Game2
Swimming
Skating
Football
Tennis
Cricket
Atheletics
Grade2
A
C
B
A
A
C
(a)
Display the names of the students who have grade C in either Game1 or Game2 or both.
(b)
Display the number of students getting grade A in Cricket.
(c)
Display the names of the students who have same game for both Game1 and Game2.
(d) Display the games taken up by the students, whose name starts with A.
(e)
Assign a value 200 for Marks for all those who are getting grade B or grade A in both Game1
and
Game2.
(f)
Arrange the whole table in the alphabetical order of Name.
(g)
Add a new column named Marks.
Q4.
Empid
010
105
152
215
244
300
335
400
441
Empid
010
105
152
215
244
300
335
400
441
Firstname
Ravi
Harry
Sam
Sarah
Manila
Robert
Ritu
Rachel
Peter
Salary
75000
65000
80000
75000
50000
45000
40000
32000
28000
Employees
Lastname
Kumar
Waltor
Tones
Ackerman
Sengupta
Samuel
Tondon
Lee
Thompson
EmpSalary
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
Benefits
15000
15000
25000
12500
12000
10000
10000
7500
7500
City
GZB
GZB
Paris
Upton
New Delhi
Washington
GZB
New York
Paris
Designation
Manager
Manager
Director
Manager
Clerk
Clerk
Clerk
Salesman
salesman
STARS
QTY
PRICE
a)
b)
c)
d)
e)
f)
g)
1
2
3
4
5
6
7
8
9
10
Drama
Horror
Drama
Comedy
Drama
Comedy
Scifi
Comedy
Comedy
Comedy
G
R
PG
PG13
R
R
PG
PG13
G
PG
Gable
Jason
Cruise
Hanks
Turner
Cruise
Ameche
Harris
Cruise
Hoffman
4
2
7
3
3
2
2
2
3
1
39.95
69.95
49.95
29.95
19.95
44.95
31.95
69.95
59.95
29.95
Find the total value of the movie cassettes available in the library.
Display a list of all movies with Price over 20 and sorted by price
Display all movies sorted by QTY in descending order.
Display a report listing movie number, current value and replacement value for each movie in the above
table. Calculate the replacement value for all movies as QTY*PRICE*1.15.
Count the number of movies where Rating is not G.
Insert a new movie in the MOV table. Fill all the columns with values.
Give the output of following SQL commands on the basis of table MOV.
Select AVG(Price) FROM MOV where Price<30;
Select MAX(Price) FROM MOV where Price>30;
Select SUM(Price*QTY) FROM MOV where QTY<4;
Select COUNT(distinct TYPE) FROM MOV
Q.7. Consider the following table MOV and answer the queries given below:
NO. ItemName
CostPerItem
Quantity
1
2
3
4
5
6
7
Computer
Printer
Scanner
Camera
Hub
UPS
Plotter
1.
2.
3.
4.
5.
6.
7.
60000
15000
18000
21000
8000
5000
25000
9
3
1
2
1
5
2
DateofPurchas
e
21/5/96
21/5/97
29/8/98
13/6/96
31/10/99
21/5/96
11/1/2000
Warranty
2
4
3
1
2
1
2
Operationa
l
7
2
1
2
1
4
2
Q8. Write the SQL commands for the following on the basis of tables INTERIORS and NEWONES
Table: INTERORS
SNO
ITEMNAME
TYPE
DATEOFSTOCK
PRICE
1
Red Rose
Double Bed
23/02/02
32000
2
Soft Touch
Baby Cot
20/1//02
9000
3
Jerrys Home
Baby Cot
19/02/02
8500
4
Rough Wood
Office Table
01/01/02
20000
5
Comfort Zone
Double Bed
12/01/02
15000
6
Jerry Look
Baby Cot
24/02/02
7000
7
Lion King
Office Table
20/02/02
16000
8
Royal Tiger
Sofa
22/02/02
30000
9
Park Sitting
Sofa
13/12/01
9000
DISCOUNT
15
10
10
20
20
19
20
25
15
10
Dine Paradise
Dining Table
19/02/02
11000
15
Table: NEWONES
SNO ITEMNAME
TYPE
DATEOFSTOCK
PRICE
DISCOUNT
11
White Wood
Double Bed
23/02/02
20000
20
12
James 007
Sofa
20/02/03
15000
15
13
Tom Look
Baby Cot
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;
Q.9 Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to
(viii): on the basis of the table
BOOKS
Book_Id
Book_Name
Author_name
Publishers
Price
Type
F0001
The Tears
William Hopkins
First Publ.
750
Fiction
F0002
Thunderbolt
Anna Roberts
First Publ.
700
Fiction
T0001
MyFirstC++
Brain & Brooke
EPB
250
Text
T0002
C++Brain
A.W. Rossaine
TDH
325
Text
C0001
Fast Cook
Lata Kapoor
EPB
350
Cooker
y
ISSUED
Book_Id
Quantity_Issued
F0001
3
T0001
1
C0001
5
(a)
(b)
(c)
(d)
(e)
(f)
(g)
(v)
Quantity
10
5
10
5
8
To show Book name, Author name and Price of books of EPB Publishers.
To list the names from books of Fiction type.
To display the names and price of the books in descending order of their price.
To increase the price of all books of First Publ. Publishers by 50.
To display the Book_Id, Book_Name and Quantity_Issued for all books which have been issued. (The query will
require contents from both the tables.)
To insert a new row in the table Issued having the following data:
F0002, 4.
Give the output:
(i)
SELECT COUNT (DISTINCT Publishers) FROM Books;
(ii)
SELECT SUM(Price) FROM Books WHERE Quantity > 5;
(iii)
SELECT Book_Name, Author_Name FROM Books WHERE Price <500;
SELECT COUNT (*) FROM Books;
Q10.Given below following table OFFICE. Write SQL queries for (i)-(iv) and give output for (vi)-(viii).
Empno
Empname
Age
Department
Sex
B_Pay
1
Ankit
45
Comp.Sc.
M
10000
2
Sumit
32
History
M
6000
3
Suchitra
23
Maths
F
9000
4
Amit
25
Geography
M
5000
5
Ankita
26
Hindi
F
8500
6
Shurti
28
Comp.Sc.
F
7200
7
Rakesh
35
Hindi
M
5900
8
i)
ii)
iii)
iv)
v)
vi)
vii)
viii)
Q11.
Q12.
Priya
33
History
F
10500
Display details of all employees belonging to History and Geography department.
Display average age of employee department wise.
Display number of employees in each department where number of employees are more than equal to 2.
Display details of all female employee belonging to various departments except in Maths and History.
Display name and age of those employees getting basic pay between 6000 and 10000.
Outputs --Select sum(B_pay) from OFFICE;
Select count (*) from OFFICE where name like A%;
Select empname from OFFICE where age in (select max(age) from OFFICE);
commands?[2]
on the basis
PRICE
30000
7000
9500
25000
25000
6500
18000
31000
9500
11500
DISC
25
20
20
30
25
15
30
30
25
25
No
11
12
13
ITEMNAME
TYPE
DATEOFSTOCK
PRICE
DISC
Wood comfort
Double bed
23/03/03
25000
25
Old fox
Sofa
20/02/03
17000
20
Milky
Baby cot
21/02/03
7500
15
b) To show all information about the baby cots from the FURNITURE
table.
c) To list the ITEMNAME which are priced at more then 15000 from the
FURNITURE table.
d) To list ITEMNAME and the type of those items, in which DATEOFSTOCK
is before 22/01/02 from the FURNITURE table in descending order of
ITEMNAME.
e) To display ITEMNAME and DATEOFSTOCK of those items, in which the
DISC percentage is more then 25 from FURNITURE table.
f) To count the number of items, whose type is SOFA from FURNITURE
table?
g) To insert a new row in ARRIVAL table.
h) Give the output of the following SQL command.
a. SELECT COUNT (DISTINCT TYPE) FROM FURNITURE
b. SELECT MAX (DISCOUNT) FROM FURNITURE WHERE TYPE=Baby cot
c. SELECT AVG (DISCOUNT) FROM ARRIVALS WHERE TYPE=D. bed
d. SELECT SUM (PRICES) FROM FURNITURE WHERE
DATEOFSTOCK<{12/02/02}
Q15. (a)What do you understand by DDL and DML. Write at least two DDL and DML coomands.
2
(b) Consider the following tables Employee and salary. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii).
6
Table : Employee
Eid
Name
Deptid
Qualification
1
Deepali Gupta
101
MCA
2
Rajat Tyagi
101
BCA
3
Hari Mohan
102
B.A
4
Harry
102
M.A
5
Sumit Mittal
103
B.Tech
6
Jyoti
101
M.Tech
Table : Salary
Eid
Basic
DA
HRA
1
6000
2000
2300
2
2000
300
300
3
1000
300
300
4
1500
390
490
5
8000
900
900
6
10000
300
490
(i)
To show the name of employees department wise.
(ii)
To list the names of those employees only whose basic is greater than 3000.
(iii)
To print the net salary from salary table where as net salary is calculated as
basic+da+hra+bonus
(iv)
To increase the bonus of all employees with 200.
(v)
Select name from employee where eid=(select eid from salary where basic= (select
max(basic) from salary));
(vi)
select Avg(basic) from salary where bonus >40;
(vii) Select count(*) from employee where sex=F;
Sex
F
M
M
M
M
F
Bonus
200
30
40
30
80
89
(viii)