|
Fall Semester 2002 Solutions are listed in some color |
This is the A114/I111 Midterm Exam for the Fall 2002 semester. The exam is open book, and open notes.
You have 50 minutes to complete it. Turn in the answers on the extra paper provided and keep the actual
exam, as there's a second part to it: tomorrow in lab you should turn in the answers to these questions
after having checked your answers in Access. Should you find any mistakes in what you turned in today,
you can improve your grade by turning in a corrected version tomorrow, with any explanations of what
you missed during the written test, and why. Best of luck and do very well!
Technicians and the other one for the Marinas.
First, here's the table of marinas (names are made up)
| Marina Number | Marina Name | Tech Number |
|---|---|---|
| Pac | Indiana Pacers | 1 |
| Lak | Los Angeles Lakers | 2 |
| Bul | Chicago Bulbs | 1 |
| Phi | Philadelphia 76ers | 1 |
And here are the technicians:
| Tech Number | Tech Name |
|---|---|
| 1 | Larry Bird |
| 2 | Phil Jackson |
(Please refer to this database for this and the next few questions).
What's the result of running the following query against this database:
SELECT [Marina Name] FROM Marina
| The answer is, of course:
|
SELECT [Marina Name] FROM Marina, Technician
| The answer for this one is
The reason is, of course, the cartesian product created. |
SELECT [Marina Name] FROM Marina, Technician WHERE Technician.[Tech Number] = Marina.[Tech Number]
| The answer for this one is
A natural join results through an adequate selection on the cartesian product. |
SELECT [Marina Name] FROM Marina, Technician WHERE Technician.[Tech Number] = Marina.[Tech Number] AND [Tech Name] = 'Larry Bird'
| The answer for this one is
Only Bird's teams are shown. |
The answer for this one is
This is almost (but not entirely) the query from no. 3.SELECT [Tech Name], [Marina Name] FROM Technician, Marina WHERE Technician.[Tech Number] = Marina.[Tech Number]; |
The answer for this one is
This one builds on the query from no. 5.SELECT [Tech Name], COUNT(*), FROM Technician, Marina WHERE Technician.[Tech Number] = Marina.[Tech Number] GROUP BY [Tech Name]; |
Larry Bird.
The answer for this one is
Again, this one builds on the query before it.SELECT [Tech Name], COUNT(*), FROM Technician, Marina WHERE Technician.[Tech Number] = Marina.[Tech Number] GROUP BY [Tech Name] HAVING [Tech Name] = 'Larry Bird'; |
SELECT [Marina Name] FROM Marina, Technician WHERE [Tech Name] = 'Larry Bird'
| This will be a selection
on a cartesian records that has eight records (four for Bird, and four
for Jackson). One for Bird and three for Jackson would be eliminated in
a natural join, but we don't have a natural join here. So the four records
for Bird will be selected, giving the same answer as question no. 3, as illustrated
below.
|
Grades):
| Name | Date | Grade |
|---|---|---|
| Larry | 10/1/2003 | 10 |
| Michael | 10/3/2003 | 8 |
| Larry | 10/5/2003 | 6 |
| Larry | 10/7/2003 | 7 |
| Michael | 10/7/2003 | 10 |
| Michael | 10/10/2003 | 8 |
Write an SQL query that lists the players and their average grades.
(The answer is: Larry 7.66, Michael 8.66).
The answer for this one is
This is a very basic query.SELECT Name, AVG(Grade) FROM Grades GROUP BY Name |
The answer for this one is
Same basic query, with calculated fields.SELECT Name, MIN(Grade), MAX(Grade), MAX(GRade) - MIN(Grade) FROM Grades GROUP BY Name |
The answer for this one is
Simple, but useful in 12 (below).SELECT AVG(Grade) FROM Grades |
The answer for this one is
Nested queries as discussed in class last Thursday.
|
Grades table?
(Name, Date) is one option. If we are allowed to change the structure of the table (nobody said we were) then adding a new column, to count the records and serve as a key, would also be an acceptable solution.
The original question was asking this: create the
|