我遇到了问题
我的查询显示了未来12周内每个资源的总工作量,并且运行良好
SELECT Tasks.ID,
Ressources.Username AS AssignedTo,
CONCAT(Year(Tasks.DueDate),
'-',
Week(Tasks.DueDate)) AS Weeks,
SUM(Tasks.ExpectedDuration) AS Durations,
Assignments.Completed
FROM Ressources INNER JOIN Assignments
ON Assignments.RessID = Ressources.ID
LEFT OUTER JOIN Tasks ON Assignments.TaskID = Tasks.ID
WHERE Assignments.Completed = 0
AND Tasks.ExpectedDuration <> 0
AND Ressources.ID IN (" . $_SESSION['MyColleagues'] . ")
AND Tasks.DueDate between NOW()
AND DATE_FORMAT(NOW() + INTERVAL 90 DAY,'%Y-%m-01')
GROUP BY AssignedTo, Week(Tasks.DueDate)
ORDER BY Weeks;
我需要添加一个名为“相反”的列。
&#39;相反&#39;是我每周所有资源的可用性,应接近40 - SUM(Tasks.ExpectedDuration)
问题在于,无论何时资源未分配特定周的任务,它都不会显示40,即可用时间。
它根本没有显示该资源的任何内容。
我试图通过LEFT JOIN来解决这个问题,但没有帮助。
这是我到目前为止所尝试的:
SELECT Tasks.ID,
Ressources.Username AS AssignedTo,
CONCAT(Year(Tasks.DueDate),
'-',
Week(Tasks.DueDate)) AS Weeks,
**40-SUM(Tasks.ExpectedDuration)** AS Durations,
Assignments.Completed
FROM Ressources **LEFT OUTER JOIN** Assignments
ON Assignments.RessID = Ressources.ID
INNER JOIN Tasks on Assignments.TaskID = Tasks.ID
WHERE Assignments.Completed = 0
AND Tasks.ExpectedDuration <> 0
AND Ressources.ID IN (" . $_SESSION['MyColleagues'] . ")
AND Tasks.DueDate between NOW()
AND DATE_FORMAT(NOW() + INTERVAL 90 DAY,'%Y-%m-01')
GROUP BY AssignedTo, Week(Tasks.DueDate)
ORDER BY Weeks;
有没有人知道如何解决这个问题?
非常感谢, 克里斯