我有一个包含分配表和员工表的数据库。每个表都包含员工ID。多个员工在同一个项目上工作,我需要能够获得每个项目ID和工作小时数的员工姓名列表。我尝试了以下但是它无法正常工作。
Select FirstName, LastName, ProjectID, HoursWorked
From employee e, assignment a
Where e.EmployeeNumber = a.EmployeeNumber
Group by projectID;
编辑:在第一个回答后,我将查询更改为:
SELECT FirstName, LastName, ProjectID, HoursWorked
FROM employee e, assignment a
Where e.EmployeeNumber = a.EmployeeNumber
GROUP BY ProjectID, FirstName, LastName;
结果很好,我不完全理解我想的那个小组。
答案 0 :(得分:1)
您需要使用聚合函数 SUM()
才能获得列的总值,
SELECT FirstName,
LastName,
ProjectID,
SUM(HoursWorked) totalHoursWorked
FROM employee e
INNER JOIN assignment a
ON e.EmployeeNumber = a.EmployeeNumber
GROUP BY FirstName, LastName, ProjectID