0% found this document useful (0 votes)
3 views

Test Generator WK

The document contains a series of SQL queries and answers related to student and sports data, billing records, and employee information. It includes instructions for writing SQL statements to extract specific information from provided tables and identifies foreign keys within those tables. Additionally, it discusses potential uses of the data and patterns in item codes for categorization.

Uploaded by

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

Test Generator WK

The document contains a series of SQL queries and answers related to student and sports data, billing records, and employee information. It includes instructions for writing SQL statements to extract specific information from provided tables and identifies foreign keys within those tables. Additionally, it discusses potential uses of the data and patterns in item codes for categorization.

Uploaded by

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

Roll No : Name of School : Time - MM- 14

Date : Name of Assessment :


Subject :
Class :

1 Answer the following questions: 4


Students
Adm No Name Class Sec R No. Address Phone
1271 Utkarsh Madam 12 C 1 C-32, Punjabi Bagh 4356154
1324 Naresh Sharma 10 A 1 31, Mohan Nagar 435654
1325 Md. Yusuf 10 A 2 12/12, Chand Nagar 145654
1328 Sumedha 10 B 23 59, Moti Nagar 4135654
1364 Subya Akhtar 11 B 13 12, Janak Puri Null
1434 Varuna 12 B 21 69, Rohini Null
1461 David DSouza 11 B 1 D-34, Model Town 243554. 98787665
2324 Satinder Singh 12 C 1 1/2, Gulmohar Park 143654
2328 Peter Jones 10 A 18 21/328, Vishal Enclave 24356154
2371 Mohini Mehta 11 C 12 37, Raja Garden 435654, 6765787
Sports
Adm No Game CoachName Grade
1324 Cricket Narendra A
1326 Volleball M.P. Singh A
1271 Volleball M.P. Singh B
1434 Basket Ball I. Malhotra B
1461 Cricket Narendra B
2328 Basket Ball I. Malhotra A
2371 Basket Ball I. Malhotra A
1271 Basket Ball I. Malhotra A
1434 Cricket Narendra A
2328 Cricket Narendra B
1364 Basket Ball I. Malhotra B
(a) Based on these tables write SQL statements for the following queries:
(i) Display the lowest and the highest classes from the table STUDENTS.

(ii) Display the number of students in each class from the table STUDENTS.
(iii) Display the number of students in class 10.
(iv) Display details of the students of Cricket team.
(v) Display the Admission number, name, class, section, and roll number of the students
whose grade in Sports table is 'A'.
(vi) Display the name and phone number of the students of class 12 who are play some
game.
(vii) Display the Number of students with each coach.
(viii) Display the names and phone numbers of the students whose grade is 'A' and
whose coach is Narendra.
(b) Identify the Foreign Keys (if any) of these tables. Justify your choices.
(c) Predict the output of each of the following SQL statements, and then verify the
output by actually entering these statements:
(i) SELECT class, sec, count(*) FROM students GROUP BY class, sec;
(ii) SELECT Game, COUNT(*) FROM Sports GROUP BY Game;]
(iii) SELECT Game FROM students, Sports WHERE students.admno = sports.admno
AND Students.AdmNo = 1434;
Ans : (a) (i) SELECT MIN(CLASS),MAX(CLASS) from student;
(ii) SELECT Class, count(*) from Student group by students;
(iii) SELECT count(*) from students where class=10;
(iv) SELECT Students.* from Students A, Sports B Where A.Admno=B.Admno
and Game="Cricket";
(v) SELECT A.Admno,name,class,section,rno from Students A, Sports B Where
A.Admno=B.Admno and grade=’A’;
(vi) SELECT name, phone from from Students A, Sports B Where
A.Admno=B.Admno and class=12;
(vii) Select coachname, count(*) from sports group by coachname;
(viii) SELECT NAME, phone from from Students A, Sports B where
A.Admno=B.Admno and coachname=’Narendra’ and grade=’A’;
(b) Foreign Key – Sports, because it is duplicating in the table. (c) (i)]
Class Sec Count(*)
10 10 11 11 12 12 A B B C B C 3 1 2 1 1 2
6 rows in set (0.08 sec) (ii)
Class Count(*)
Basket Ball
442
Cricket Volleball
3 rows in set (0.03 sec) (iii)
Game Name Address
31, Mohan Nagar
Cricket Naresh Sharma
12, Janak Puri
Volleball Subya Akhtar
21/32B, Vishali
Basket Ball Peter Jones
Enclave
Basket Ball Mohini Mehta
37, Raja Garden
Cricket Varuna
69, Rohini
5 rows in set (0.00 sec)
2 Answer the following questions. 5
Bills
Bill No Date I_Code qty
1 2010-04-01 1002 2
1 2010-04-01 3001 1
2 2010-04-01 1001 3
2 2010-04-01 1002 1
2 2010-04-01 2003 2
3 2010-04-02 2002 1
4 2010-04-02 2002 4
4 2010-04-02 2003 2
5 2010-04-03 2003 2
5 2010-04-03 3001 1
5 2010-04-03 3002 3
Items
I_Code Name Category
1001 2010-04-01 1002
1002 2010-04-01 3001
1003 2010-04-01 1001
2001 2010-04-01 1002
2002 2010-04-01 2003
2003 2010-04-02 2002
3001 2010-04-02 2002
3002 2010-04-02 2003
(a) Based on these tables write SQL statements for the following queries:
(i) Display the average rate of a South Indian item.
(ii) Display the number of items in each category.
(iii) Display the total quantity sold for each item.
(iv) Display total quantity of each item sold but don't display this data for the items
whose total quantity sold is less than 3.
(v) Display the details of bill records along with Name of each corresponding item.
(v) Display the details of the bill records for which the item is 'Dosa'.
(vi) Display the details of the bill records for which the item is 'Dosa'.
(vii) Display the bill records for each Italian item sold.
(viii) Display the total value of items sold for each bill.
(b) Identify the Foreign Keys (if any) of these tables. Justify your answer.
(c) Answer with justification (Think independently. More than one answers may be
correct. It all depends on your logical thinking):
(i) Is it easy to remember the Category of item with a given item code? Do you find
any kind of pattern in the items code? What could be the item code of another South
Indian item?
(ii) What can be the possible uses of Bills table? Can it be used for some analysis
purpose?
(iii) Do you find any columns in these tables which can be NULL? Is there any column
which must not be NULL?

Ans : (a) (i)

(ii)

(iii)

(iv)

(v)

(vi)

(vii)

(viii)

(b) I_Code is the foreign key among these tables. This is because, I_Code is used to
link the two tables and it is a primary key for Items table.
(c) (i) Yes, it is easy to remember the category of item with a given item code. There
is a kind of pattern in the item codes, South Indian dishes must be in the range
from 1000 to 1999, Chinese dishes must be in the range of 2000 to 2999 and Italian
food must be in the range of 3000 to 3999. The code of another South Indian item
could be 1004.
(ii) The possible uses of BILLS table can be: 1. Maintenance of bill records.
2. Maintenance of sale records. 3. Legal proof.
Yes, it can be used for some analysis purpose also. We can find overtime sales of the
items or a particular item.
(iii) No. None of the columns in the table can be NULL.
3 Answer the following questions. 5
Table: Employee
No Name Salary Zone Age Grade Dept
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
3 Naveen 32000 West 40 20
4 Uday 38000 North 38 C 30
5 Nupur 32000 East 26 20
6 Moksh 37000 South 28 B 10
7 Shelly 36000 North 26 A 30
Table: Department
No DName MinSal MaxSal HOD
10 Sales 25000 32000 1
20 Finance 30000 50000 5
30 Admin 25000 40000 7
(a) Based on these tables write SQL statements for the following queries:
(i) Display the details of all the employees who work in Sales department.
(ii) Display the Salary, Zone, and Grade of all the employees whose HOD is Nupur.
(iii) Display the Name and Department Name of all the employees.
(iv) Display the names of all the employees whose salary is not within the specified
range for the corresponding department.
(v) Display the name of the department and the name of the corresponding HOD for
all the departments.
(b) Identify the Foreign Keys (if any) of these tables. Justify your choices.
Ans : (a) (i)

(ii)

(iii)

(iv)

(v)

(b) Dept is the foreign key for these tables. This is because, Dept is used to link the
two tables and it is a primary key for one of the tables.

You might also like