我遇到了数据库问题。我已经使用2014年冒险作品复制了它。空白表结果
我想显示BusinessEntityID多次显示的所有结果。因此,如果用户是两个部门的成员,他们的ID将显示两次
SELECT Person.FirstName,
Person.LastName,
HumanResources.Department.Name AS CurrentDepartment,
StartDate,
EndDate
FROM AdventureWorks2014.Person.Person
JOIN HumanResources.EmployeeDepartmentHistory
ON HumanResources.EmployeeDepartmentHistory.BusinessEntityID = Person.BusinessEntityID
JOIN HumanResources.Department
ON EmployeeDepartmentHistory.DepartmentID = HumanResources.Department.DepartmentID
GROUP BY Person.BusinessEntityID,
HumanResources.Department.DepartmentID,
Person.FirstName,
Person.LastName,
HumanResources.Department.Name,
StartDate,
EndDate
HAVING COUNT(Person.BusinessEntityID) > 1
ORDER BY Person.LastName, StartDate
我删除了有我得到返回的结果(整个表)。所以我想我知道问题不在于它是什么/如何解决它。
,请复制粘贴您的样本输入数据。它会帮助每个人轻松理解这个问题。 – Tajinder
因此,基于该分组和那些数据,您期望查询返回什么结果? – HoneyBadger
我期望它返回第一个屏幕截图,但我得到第二个 – Phil3992