Assignment3 Solution
Assignment3 Solution
Assignment3 Solution
a. Print the names and ages of each employee who works in both the Hardware
department and the Software department.
b. 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.
c. Print the name of each employee whose salary exceeds the budget of all of the
departments that he or she works in.
d. Find the managerids of managers who manage only departments with budgets
greater than $1 million.
e. Find the enames of managers who manage the departments with the largest
budgets.
f. 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.
g. Find the managerids of managers who control the largest amounts.
h. 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.
Ans:
a. SELECT E.ename, E.age
FROM Emp E, Works W1, Works W2, Dept D1, Dept D2
WHERE E.eid = W1.eid AND W1.did = D1.did AND D1.dname = ‘Hardware’ AND
E.eid = W2.eid AND W2.did = D2.did AND D2.dname = ‘Software’
e. SELECT E.ename
FROM Emp E
WHERE E.eid IN (SELECT D.managerid
FROM Dept D
WHERE D.budget = (SELECT MAX (D2.budget)
FROM Dept D2))
f. SELECT D.managerid
FROM Dept D
WHERE 5000000 < (SELECT SUM (D2.budget)
FROM Dept D2
WHERE D2.managerid = D.managerid )
h. SELECT E.ename
FROM Emp E, Dept D
WHERE E.eid = D.managerid GROUP BY E.Eid, E.ename
HAVING EVERY (D.budget > 1000000) AND ANY (D.budget < 5000000)