COMP353 ASSIGNMENT 3

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (1 vote)

Exercise #1
Consider the Flight database below:
Airport (airportCode, city, state)
FlightLeg (legNum, flightID)
Flights {flightID, flightName)
FlightAgents (agentID, flightID, Fare)
Orders (orderID, agentID, flightID, num_of_tickets)
Details (airportCode, legNum, bookedDate, duration)
Agents (agentID, agentName)

Express the following queries in SQL. State any assumption you make in case you feel
there is any ambiguity in the question.

1. Agents Tom and Jerry takes care of which flights? Select Flights.flightName
2. Which flight has the longest duration? Select Distinct Flights.flightName,
MAX(Details.duration)

3. Which agents can take care of all the flights mentioned in the inventory? Select
Agents.agentID, Agents.agentName

4. Determine for each flight agent, the number of flights booked, present in the
inventory? Select Agents.agentName, COUNT(FlightAgents.flightID),
COUNT(FlightLeg.flightID)

5. For which flights, there have been more than 100 tickets ordered? Select
Orders.flightID, Flight.flightName, SUM(Orders.Num_of_tickets)

6. Which flights booked Air Canada or booked a flight managed by Tom? Select
Distinct Airport.city

7. Which flights booked flights for a duration of at least 10 days? Select
Airport.airportCode, Airport.city, Airport.state

8. Which flights were booked exactly twice to any flight(s)? Do not use aggregate
function count for this query. Select Flights.flightName

Exercise #2
Consider the following relational schema. An employee can work in more than one
department; the pct_time filed of the Works relation shows the percentage of time that a
given employee works in a given department.
Emp (eid: integer, ename: string, age: integer, salary: real)
Works (eid: integer, did: integer, pct_time: integer)
Dept (did: integer, dname: string, budget: real, managerid: integer)

Write the following queries in SQL:
1. Print the names and ages of each employee who works in both the Hardware
department and the Software department. Select Emp.ename, Emp.age

2. For each department with more than 20 full-time-equivalent employees (i.e.,
where the part-time and full-time employees add up to at least that many full-time
employees), print the “did” together with the number of employees that work in
that department. Select Works.did, COUNT (Works.eid)

3. Print the name of each employee whose salary exceeds the budget of all of the
departments that he or she works in. Select Emp.ename

4. Find the “managerids” of managers who manage only departments with budgets
greater than $1 million. Select Distinct Dept.managerid

5. Find the “enames” of managers who manage the departments with the largest
budgets. Select Emp.ename

6. If a manager manages more than one department, he or she controls the sum of all
the budgets for those departments. Find the “managerids” of managers who
control more than $5 million. Select Dept.managerid

7. Find the “managerids” of managers who control the largest amounts.
Here you can create a view as follows:

CREATE VIEW Manager AS
SELECT DISTINCT D.managerid, SUM (D.budget) AS tempBudget
FROM Dept D
GROUP BY D.managerid;
And then you can use the view Manager in the query
Select Distinct managerid
FROM Manager
WHERE tempBudget =

8. Find the “enames” of managers who manage only departments with budgets
larger than $1 million, but at least one department with budget less than $5
million. Select Emp.Eid, Emp.ename

Submitting Assignment #3
– Naming convention for Notepad++ file: Create one .sql file, containing your
solution file for your assignment using the following naming convention:
The file .sql should be called A3_Team_Name, where Team_Name is
your student group name.

– Submit your file .sql in the appropriate assignment folder via ENCS Website. The
deadline is not respected would be discarded and no replacement submission will
be allowed.

– Submit only ONE version of an assignment for each team. It is not an individual
submission. If more than one version is submitted the last one, before the deadline
date, will be graded and all others will be disregarded.

Evaluation Criteria of Assignment #3 (100 points)
Activities Points
Exercise #1: 50 pts.
Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8 50 pts.
Exercise #2: 50 pts.
Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8 50 pts.