我想知道从三个表中获取信息的最佳方法是什么。我想要展示的是按项目计算所有员工的数量,并将其与项目名称和pnumber相关联。我发现哪个员工来自WORKS_ON tbl哪个项目,该项目包含Essn(与EMPLOYEE TABLE WITH SNN匹配)和Pno(与项目Ttables pnumber匹配)的记录。
我这样做了:
Select pno, count(*) as empnum
FROM WORKS_ON work inner join employee emp inner join project
on work.essn=emp.ssn
group by work.pno
where pnumber in
(select pno from WORKS_ON)
我知道这是错的,但不知道该去哪里。
编辑: 然后我尝试了
SELECT
project, employee
inner join works_on on WORKS_ON.essn = EMPLOYEE.SSN
INNER JOIN WORKS_ON on works_on.pno = PROJECT.pnumber
GROUP BY
PROJECT.Pnumber
但仍然没有去。它说project.pnumber无效标识符
答案 0 :(得分:0)
你关闭了。您需要加入项目表,如下所示
SELECT
PROJECT.PNUmber,
COUNT(*)
INNER JOIN WORKS_ON on EMPLOYEE.SSN = WORKS_ON.essn
INNER JOIN PROJECT on WORKS_ON.pno = PROJECT.pnumber
GROUP BY PROJECT.Pnumber