Ms Query Query Group按员工ID

时间:2015-12-21 16:44:09

标签: sql vba ms-access

如果我不使用groupby [Service Order Labor].EmployeeID条款

,我写了这个查询,显示了所需的输出

我想要实现的是列出分配给员工的所有工作单,因此如果一个员工有多个记录,则应将其写为一组

SELECT [Service Order Labor].WorkorderLaborID, [Service Order Labor].WorkorderID, Customers.ID AS CustomerID, Customers.SiteName AS Customer, [Service Orders].ProblemDescription, Employees.[EmployeeID#] AS EmployeeID, Employees.EmployeeName, [Service Order Labor].SERVICED AS StartDate, [Service Orders].DateFinished AS CompletedDate, [Service Order Labor].DISPATCH, [Service Types].Type, [Service Orders].[PRIORITY#], [Service Orders].COMPLETE, [Service Order Labor].ACTIVE
FROM (((Customers INNER JOIN [Service Orders] ON Customers.ID = [Service Orders].ID) INNER JOIN [Service Order Labor] ON [Service Orders].WorkorderID = [Service Order Labor].WorkorderID) INNER JOIN Employees ON [Service Order Labor].EmployeeID = Employees.[EmployeeID#]) INNER JOIN [Service Types] ON [Service Orders].Type = [Service Types].TypeID
ORDER BY [Service Order Labor].SERVICED, [Service Order Labor].WorkorderID group by  [Service Order Labor].EmployeeID;

错误

enter image description here

1 个答案:

答案 0 :(得分:1)

你可以退休一些“(”尝试:

 SELECT  [Service ORDER Labor].WorkorderLaborID,
     [Service ORDER Labor].WorkorderID,
     Customers.ID       AS CustomerID,
     Customers.SiteName AS Customer,
     [Service Orders].ProblemDescription,
     Employees.[EmployeeID#] AS EmployeeID,
     Employees.EmployeeName,
     [Service ORDER Labor].SERVICED AS StartDate,
     [Service Orders].DateFinished  AS CompletedDate,
     [Service ORDER Labor].DISPATCH,
     [Service Types].Type,
     [Service Orders].[PRIORITY#],
     [Service Orders].COMPLETE,
     [Service ORDER Labor].ACTIVE
FROM Customers
INNER JOIN [Service Orders]       ON (Customers.ID = [Service Orders].ID)
INNER JOIN [Service ORDER Labor]  ON ([Service Orders].WorkorderID = [Service ORDER Labor].WorkorderID)
INNER JOIN Employees              ON ([Service ORDER Labor].EmployeeID = Employees.[EmployeeID#])
INNER JOIN [Service Types]        ON ([Service Orders].Type = [Service Types].TypeID)
ORDER BY
  [Service ORDER Labor].SERVICED,
  [Service ORDER Labor].WorkorderID 
group by 
  [Service ORDER Labor].EmployeeID;