无法限制一条数据多次出现的数据集
Trouble limiting data set where a piece of data occurs more than once
SELECT FirstName, LastName, [description], ProjectName, StartOnDate, FinishOnDate
FROM Assignments AS A
JOIN Projects AS P ON A.ProjectID = P.ProjectID
JOIN Positions AS PO ON A.PositionCode = Po.PositionCode
JOIN Employees AS E ON E.EmployeeID = A.EmployeeID
这些是我需要的列,但我只需要出现两次的行。具体来说,我只需要有多个任务的员工。
下一个代码为我提供了重复的结果,但我似乎无法加入我正在寻找的结果集的其余表列。
SELECT A.EmployeeID
FROM Assignments AS A
GROUP BY A.EmployeeID
HAVING COUNT(A.EmployeeID) > 1
该代码将 return 由 where 语句的子查询识别的每个员工的项目和职位。
SELECT FirstName, LastName, [description], ProjectName, StartOnDate, FinishOnDate
FROM Assignments AS A
JOIN Projects AS P ON A.ProjectID = P.ProjectID
JOIN Positions AS PO ON A.PositionCode = Po.PositionCode
JOIN Employees AS E ON E.EmployeeID = A.EmployeeID
WHERE EmployeeID in (SELECT A.EmployeeID
FROM Assignments AS A
GROUP BY A.EmployeeID
HAVING COUNT(A.EmployeeID) > 1)
如果你没有庞大的数据集,你可以用困难的方式来做:
Select EmployeeID, FirstName, LastName, [description], ProjectName, StartOnDate,
FinishOnDate from (
SELECT EmployeeID, FirstName, LastName, [description], ProjectName, StartOnDate, FinishOnDate
FROM Assignments AS A
JOIN Projects AS P ON A.ProjectID = P.ProjectID
JOIN Positions AS PO ON A.PositionCode = Po.PositionCode
JOIN Employees AS E ON E.EmployeeID = A.EmployeeID) B
group by GROUP B.EmployeeID
HAVING COUNT(B.EmployeeID) > 1
SELECT FirstName, LastName, [description], ProjectName, StartOnDate, FinishOnDate
FROM Assignments AS A
JOIN Projects AS P ON A.ProjectID = P.ProjectID
JOIN Positions AS PO ON A.PositionCode = Po.PositionCode
JOIN Employees AS E ON E.EmployeeID = A.EmployeeID
这些是我需要的列,但我只需要出现两次的行。具体来说,我只需要有多个任务的员工。
下一个代码为我提供了重复的结果,但我似乎无法加入我正在寻找的结果集的其余表列。
SELECT A.EmployeeID
FROM Assignments AS A
GROUP BY A.EmployeeID
HAVING COUNT(A.EmployeeID) > 1
该代码将 return 由 where 语句的子查询识别的每个员工的项目和职位。
SELECT FirstName, LastName, [description], ProjectName, StartOnDate, FinishOnDate
FROM Assignments AS A
JOIN Projects AS P ON A.ProjectID = P.ProjectID
JOIN Positions AS PO ON A.PositionCode = Po.PositionCode
JOIN Employees AS E ON E.EmployeeID = A.EmployeeID
WHERE EmployeeID in (SELECT A.EmployeeID
FROM Assignments AS A
GROUP BY A.EmployeeID
HAVING COUNT(A.EmployeeID) > 1)
如果你没有庞大的数据集,你可以用困难的方式来做:
Select EmployeeID, FirstName, LastName, [description], ProjectName, StartOnDate,
FinishOnDate from (
SELECT EmployeeID, FirstName, LastName, [description], ProjectName, StartOnDate, FinishOnDate
FROM Assignments AS A
JOIN Projects AS P ON A.ProjectID = P.ProjectID
JOIN Positions AS PO ON A.PositionCode = Po.PositionCode
JOIN Employees AS E ON E.EmployeeID = A.EmployeeID) B
group by GROUP B.EmployeeID
HAVING COUNT(B.EmployeeID) > 1