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

Lab Assignment-9: Consider The Following Tables: Table Student

The document describes tables for students, classes, class enrollments, and faculty. It provides sample data and asks 10 multi-part questions about querying the tables to return names, ages, class details, enrollments, rooms, and other attributes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Lab Assignment-9: Consider The Following Tables: Table Student

The document describes tables for students, classes, class enrollments, and faculty. It provides sample data and asks 10 multi-part questions about querying the tables to return names, ages, class details, enrollments, rooms, and other attributes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Assignment-9

Consider the following tables:

Table Student:
+------+---------+---------+-------+------+
| snum | sname | major | level | age |
+------+---------+---------+-------+------+
| 101 | Jhon | CS | SR | 19 |
| 102 | Smith | CS | JR | 20 |
| 103 | Jacob | ECE | SR | 20 |
| 104 | Tom | CS | JR | 20 |
| 105 | Sid | CS | JR | 20 |
| 106 | Harry | History | SR | 21 |
| 107 | Hellen | CS | JR | 21 |
| 108 | Bob | English | SR | 22 |
| 109 | Andy | ECE | JR | 21 |
| 110 | Charles | History | SR | 23 |
+------+---------+---------+-------+------+

Table Class:
+--------+----------+------+------+
| cname | meets_at | room | fid |
+--------+----------+------+------+
| CSC342 | Morning | R128 | 201 |
| CSC343 | Noon | R128 | 203 |
| CSC345 | Night | R154 | 204 |
| ECE300 | Morning | R111 | 202 |
| ECE301 | Noon | R111 | 203 |
| ENG366 | Morning | R154 | 203 |
| ENG367 | Evening | R111 | 205 |
| HIS320 | Evening | R128 | 205 |
+--------+----------+------+------+
Table Enrolled:
+------+--------+
| snum | cname |
+------+--------+
| 101 | CSC342 |
| 101 | CSC343 |
| 101 | CSC345 |
| 101 | ECE300 |
| 101 | ENG366 |
| 102 | CSC343 |
| 102 | CSC345 |
| 102 | ECE301 |
| 103 | ECE300 |
| 103 | ECE301 |
| 104 | CSC342 |
| 104 | ECE301 |
| 105 | CSC345 |
| 105 | ECE300 |
| 106 | ENG366 |
| 106 | HIS320 |
| 107 | CSC342 |
| 107 | ENG366 |
| 108 | ENG367 |
| 108 | HIS320 |
| 109 | ECE300 |
| 109 | ECE301 |
| 110 | ENG366 |
| 110 | HIS320 |
+------+--------+

Table Faculty:
+-----+-----------+--------+
| fid | fname | deptid |
+-----+-----------+--------+
| 201 | S. Jackson| 301 |
| 202 | M. Shanks | 302 |
| 203 | I. Teach | 302 |
| 204 | A. Zobrah | 303 |
| 205 | M. Jensen | 303 |
+-----+-----------+--------+

The meaning of these relations is straightforward; for example, Enrolled has one
record per student-class pair such that the student is enrolled in the class.

Write the SQL statements required to create these relations, including


appropriate versions of all primary and foreign key integrity constraints.

Read all questions first and insert values accordingly.


No duplicates should be printed in any of the

answers. Write the following queries in SQL:

1. Find the names of all Juniors(Level = JR) who are enrolled in a class
taught by I. Teach.

2. Find the age of the oldest student who is either a History major or
enrolled in a course taught by I. Teach.

3. Find the names of all classes that either meet in room R128 or
have five or more students enrolled.

4. Find the names of all students who are enrolled in two class that
meet at the same time.

5. Find the names of faculty members who teach in every room in


which some class is taught.

6. Find the names of faculty members for whom the combined


enrollment of the course that they teach is less than five.

7. For each level, print the level and the average age of students for that
level.

8. For all levels except JR, print the level and the average age of
students for that level.

9. For each faculty member that has taught class only in room R128
print the faculty member’s name and the total number of classes he
or she has taught.

10. Find the names of students enrolled in the maximum number of


classes.

You might also like