Employee(SSN, name, salary, DNo)
Department(DNo, DeptName, MgrSSN)
Project(PNo, location, ProjName)
HourLog(SSN, PNo, hours)
The Employee relation provides a list of employees with their SSN, name, salary, and department number (DNo). The SSN is unique for each employee. Each employee belongs to only one department. The Department relation contains a list of the departments for the company. Its schema includes a unique department number called DNo. It also includes the name of the department (DeptName) and the social security number of the department's manager (MgrSSN). Each department has a only one manager. The Project relation includes a unique project number (PNo), location and the project name (ProjName). An employee can be assigned to any number (including zero) projects. Each project has at least one person assigned to it. Finally, the HourLog relation lists for each project the number of hours of work for each employee who is assigned to that project. The key of this relation is SSN and PNo. Write the following queries in SQL.
BookAuthor(book, author, earnings)
BookReference(book, referencedBook, times)
BookReview(book, reviewer, score)
BookPublish(book, year, publisher, price, num)
In this database, each book may have one or more authors and each author may make a different amount of money from that book. One book may make reference to other books. One book may be reviewed by different reviewers and get different scores. An author could also be a reviewer and a publisher.
Write the following queries in SQL.
Student(ID, name, dept, status) // status = "grad" or "undergrad"Write the following in SQL:
// ID is a key
RA(ID, advisor, dept) // (ID,advisor) together are a key
TA(ID, course, dept) // (ID,course) together are a key
| from | to | cost | airline |
|---|---|---|---|
| SF | Denver | 300 | Frontier |
| SF | Denver | 350 | United |
| Denver | SF | 250 | United |
| Denver | SF | 250 | Frontier |
| Denver | Chicago | 250 | American |
| Chicago | NY | 250 | Delta |
| Denver | NY | 500 | American |
| Denver | NY | 400 | TWA |
| SF | NY | 750 | United |
(a) Give a single SQL query that returns the cost of the cheapest nonstop flight between each pair of cities. For example, the result over the above relation instance should be:
| from | to | cost |
|---|---|---|
| SF | Denver | 300 |
| Denver | SF | 250 |
| Denver | Chicago | 250 |
| Chicago | NY | 250 |
| Denver | NY | 400 |
| SF | NY | 750 |
(b) Give a single SQL query that returns the cheapest cost of flying between each pair of cities assuming we are willing to stop up to two times en-route. For example, by stopping once (in Denver), we can get from SF to NY for 700 instead of 750. With this example data, we could stop twice (in Denver and Chicago), but that would be more expensive ($300+$250+$250 = $800).
(c) Is it possible to write a single SQL query that returns the cheapest cost of flying between each pair of cities regardless of the number of stops? If so, give the query. If not, briefly explain why.