CS 386/586 Winter 2009 – Exercise 1– January 6, 2009
Work through the
exercises
Undergraduate students, please turn in your paper (with papers from all other
exercises) at the end of the quarter.
|
Teacher table: |
|||
|
Number |
Name |
Office |
|
|
1 |
Lois |
O12 |
|
|
2 |
James |
O14 |
|
|
3 |
Sally |
O55 |
|
|
Course table: |
||
|
Number |
Name |
Description |
|
386 |
Intro to Databases |
Introduction to relational database management systems |
|
161 |
Intro to Computer Science 1 |
Introduction to problem-solving, algorithm and program design |
|
Can-teach table: |
|
|
Course |
Teacher |
|
386 |
1 |
|
386 |
2 |
|
161 |
2 |
6. Show the query answer for each of the following queries:
SELECT *
FROM Teacher,
Can-teach;
7. SELECT *
FROM Teacher, Can-teach
WHERE Teacher.Number
= Can-teach.Teacher;
8. SELECT *
FROM Teacher, Can-teach
WHERE Can-teach.Course < 300 AND Teacher.Number
= Can-teach.Teacher;
9. SELECT *
FROM Teacher T,
Can-teach CT, Course C
WHERE T.Number
= CT.Teacher AND CT.Course
= C.Number;
10.
SELECT T.Name, C.Name
FROM Teacher T,
Can-teach CT, Course C
WHERE T.Number
= CT.Teacher AND CT.Course
= C.Number;
12. Write
an SQL query (for the above database) that lists the name of the employee and
the number of the parking space, for every employee that has an assigned
parking space.
13. (Bonus)
Write an SQL query for the above database that lists the office number for each
office that has at least two employees assigned. Make sure that each office number (that has
at least two employees assigned) is listed just once in your query answer.