JAVA NET BEANS - Call For Classes - 9717570033 - SQL PRACTICE QUESTIONS 2
JAVA NET BEANS - Call For Classes - 9717570033 - SQL PRACTICE QUESTIONS 2
9717570033
Sunday 12 August 2012
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 1 of 10
:
+-----+-----------+----------+-----+
a) Based on these tables write SQL statements for the following queries:
i Display the lowest and the highest classes from the table STUDENTS.
mysql> select max(class) as "highest", min(class) as "lowest" from students;
ii Display the number of students in each class
from the table STUDENTS.
mysql> select class,count(class) as "No.of Students" from student group by class;
iii Display the number of students in class 10.
mysql> select count(class) from students where class = 10;
iv Display details of the students of Cricket team
mysql> select student.* from students,sports where students.admno=sports.admno
and game='Cricket';
mysql> select student.* from students join sports using(admno) where
game='Cricket';
v Display the Admission number, name, class, section, and roll number of the students
whose grade in Sports table is 'A'.
mysql> select students.admno,name,class,sec,rno from students,sports where
students.admno=sports.admno and grade='A';
mysql> select students.admno,name,class,sec,rno from students join sports
using(admno) where grade='A';
vi Display the name and phone number of the students of class 12 who play some game.
mysql> select name,phone from students,sports where students.admno=sports.admno
and class=12 and game is not null;
mysql> select name,phone from students join sports using(admno) where class=12
and game is not null;
vii Display the Number of students with each coach.
mysql> select coachname,count(admno) from sports group by coachname;
viii Display the names and phone numbers of the students whose grade is 'A' and whose
coach is Narendra.
mysql> select name,phone from students,sports where students.admno=sports.admno
and grade='A'and coachname='Narendra';
mysql> select name,phone from students join sports using(admno) where
grade='A'and coachname='Narendra';
b) Identify the Foreign Keys (if any) of these
tables. Justify your choices.
Admno is the Foreign Key in Sports table, because it’s the only column/field in
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 2 of 10
:
common to join the two given tables.
c) Predict the output of each of the following SQL statements, verify the output by
actually entering these statements:
i SELECT class, sec, count(*) FROM students
GROUP BY class, sec;
+-------+------+----------+
| class | sec | count(*) |
+-------+------+----------+
| 10 | A | 3|
| 10 | B | 1|
| 11 | B | 2|
| 11 | C | 1|
| 12 | B | 1|
| 12 | C | 2|
+-------+------+----------+
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 3 of 10
:
+-------------+
| Basket Ball |
| Cricket |
+-------------+
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 4 of 10
:
items.I_code=bills.I_code and name like '%Dosa';
mysql> select billno,datee,bills.I_code,qty from items join bills using(I_code) where
name like '%Dosa';
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 5 of 10
:
|Owner |varchar(30)|YES | | |Ch_Date |date |YES | | |Challan_Amt |int(4) |YES | |NULL |
|Address|varchar(50)|YES | | |RegNo |char(10)|YES | | +------------+-----------+----+---+-------+
+-------+-----------+----+---+ |Offence_Code|int(3) |YES |
|
+------------+--------+----+---+
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 6 of 10
:
viii Display details of each challan alongwith vehicle details, Off_desc, and
Challan_Amt.
mysql> select * from vehicle,challan,offence where vehicle.RegNo=challan.RegNo
and challan.Offence_code=offence.offence_code ;
b) Identify the Foreign Keys (if any) of these tables. Justify your choices.
RegNo, Offence_Code are the two foreign keys in the table Challan.
c) Should any of these tables have some more column(s)? Think, discuss in peer
groups, and discuss with your teacher.
No, Not Required
DEPARTMENT EMPLOYEE
+------+---------+--------+--------+------+ +----+---------+--------+--------+------+-------+------
| Dept | DName | MinSal | MaxSal | HOD | +
+------+---------+--------+--------+------+ | No | Name | Salary | Zone | Age | Grade | Dept
| 10 | Sales | 25000 | 32000 | 1| |
| 20 | Finance | 30000 | 50000 | 5| +----+---------+--------+--------+------+-------+------
| 30 | Admin | 25000 | 40000 | 7| +
+------+---------+--------+--------+------+ | 1 | Mukul | 30000 | West | 28 | A | 10 |
| 2 | Kritika | 35000 | Centre | 30 | A | 10 |
| 3 | Naveen | 32000 | West | 40 | NULL | 20 |
| 4 | Uday | 38000 | North | 38 | C | 30 |
| 5 | Nupur | 32000 | East | 26 | NULL | 20 |
| 6 | Moksh | 37000 | South | 28 | B | 10 |
| 7 | Shelly | 36000 | North | 26 | A | 30 |
+----+---------+--------+--------+------+-------+------
+
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.
mysql> select * from employee where dept=(select dept from department where
dname='Sales');
ii Display the Salary, Zone, and Grade of all the employees whose HOD is Nupur.
mysql> select salary,zone,grade from employee where dept=(select dept from
department where hod=(select no from employee where name='Nupur'));
iii Display the Name and Department Name of all
the employees.
mysql> select name,dname from employee,department where
employee.dept=department.dept;
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 7 of 10
:
iv Display the names of all the employees whose salary is not within the specified range
for the corresponding department.
mysql> select name from employee,department where
employee.dept=department.dept and salary between minsal and maxsal;
V Display the name of the department and the name of the corresponding HOD for all
the departments.
mysql> select dname,name from department,employee where hod=no;
b) Identify the Foreign Keys (if any) of these tables. Justify your choices.
Dept is the Foreign Key in Employee table, because it’s the only column/field in
common to join the two given tables.
Unknown at 06:15
Share
8 comments:
Reply
Replies
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 8 of 10
:
Unknown 9 July 2019 at 07:41
its all correct
the page you suggested needs corrections i checked there are many mistakes.
Reply
Replies
Reply
Home
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 9 of 10
:
‹ View web version
›
About Me
Unknown
View my complete profile
Powered by Blogger.
http://javanetbeansnotes.blogspot.com/2012/08/sql-practice-questions-2.html?m=1 14/05/24, 22 39
Page 10 of 10
: