上传者: wzqzjc
|
上传时间: 2022-09-12 10:30:55
|
文件大小: 43KB
|
文件类型: DOC
一些习题,有助于加深SQL查询。
Relational algebra and SQL Query
Consider the following schema of a company database:
Employees(eid, ename, address, supereid)
Departments(did, dname)
Projects(pid, pname, did)
Works_on(eid, pid, hours)
(1)For each employee, find his/her name and the name of his/her supervisor.
(2) Find the pid of projects of the department with dname = “Toys” for which at least two different Employees work.
(3) Find the eids of employees who work on a project of every department, i.e. find the eids of employees who work for at least a project of every department.
Answer:
(SELECT E.eid
FROM Employees E
WHERE NOT EXISTS
(SELECT *
FROM Departments D
WHERE NOT EXISTS
(SELECT *
FROM Projects P, Works_on W
WHERE W.pid = P.pid AND P.did = D.did AND W.eid = E.eid)))
………………………………
………………………………