0

我正在尝试查找每种类型所有者的工作时间总和,不包括 ExperienceLevel 为“初级”的员工的服务和少于 3 名成员的任何 ExperienceLevel 类型。我一直在努力解决这个问题,但无法得到答案......

表格:

OWNER ( OwnerID, OwnerName, OwnerEmail, OwnerType )
PROPERTY ( PropertyID, PropertyName, Street, City, State, Zip, OwnerID )
EMPLOYEE ( EmployeeID, LastName, FirstName, CellPhone, ExperienceLevel )
SERVICE ( PropertyID, EmployeeID, ServiceDate, HoursWorked )

我的最新查询:

SELECT OwnerType, SUM(HoursWorked) AS SumOfHoursWorked
 FROM EMPLOYEE, SERVICE, OWNER
 WHERE EMPLOYEE.EmployeeID = SERVICE.EmployeeID 
 AND EMPLOYEE.ExperienceLevel <> 'Junior'
 AND (SELECT COUNT(ExperienceLevel) > 2)
4

1 回答 1

0

select 语句中的所有表之间都需要有连接条件,并且您只限定员工和服务之间的连接。

此外

where employee.employeeid = service.employeeid 

添加

and service.propertyid = property.propertyId 
and property.ownerid = owner.ownerid  

正如米海的评论所建议的

and employee.experiencelevel in (select experiencelevel from employee having count(*) > 2)

最后,如果对这些值进行分组,总和会更好。

group by ownertype;
于 2013-10-16T02:09:48.800 回答