我发现解决以下问题有点令人困惑......
” 员工可能被分配到多个项目,而项目可能有许多员工。请考虑以下关系模式,并为以下查询编写SQL语句。
Employees (empID, empName, empDOB, empAddress, salary, deptID, jobID)
Assignments (empID, projID, assignedDate, completionDate, status)`
Projects (projID, projDescription, startDate, endDate, projType)
(a)显示1980年1月31日之前出生并分配了“办公楼”类型项目的员工姓名,按姓名的升序排序结果。
(b)检索至少分配了两(2)个项目的empID。 “
到目前为止我的答案。
(a)SELECT empName FROM EMPLOYEES WHERE empDOB < '31-january-1980' AND ....
“
请帮帮我
答案 0 :(得分:-1)
试试这个: A)
SELECT employee.empName
FROM Assignments ass
JOIN Employees employee
ON employee .empID= ass.empID
JOIN Projects project
ON project.projID= ass .projID
WHERE employee.empDOB < '31-january-1980'
AND project.projType = ‘Office Complex’
ORDER BY employee.empName;
不使用JOIN
条款
SELECT DISTINCT employee.empName
FROM Employees employee
WHERE employee.empDOB < '31-january-1980'
AND employee.empID IN (
SELECT ass.empID
FROM Assignments ass
WHERE ass.projID IN (
SELECT project.projID
FROM Projects project
WHERE project.projType = ‘Office Complex’
)
)
ORDER BY employee.empName ASC;
b)中
SELECT ass.empID, COUNT(*) as counting
FROM Assignments ass
GROUP BY ass.empID
HAVING COUNT(*) >= 2;