我遇到了这个问题我正在尝试获取与项目相关的上一个任务更新任务以及如何通过获取最后一个计费时间来更新 我也有Copley的设计问题
我的查询:
SELECT p.projectID, p.projectName, t.lastUpdate, billingsTimes.userID
FROM Tasks AS t INNER JOIN
Projects_tasks ON t.taskID = Projects_tasks.taskID INNER JOIN
Projects AS p ON Projects_tasks.projectID = p.projectID INNER JOIN
billingsTimes ON t.taskID = billingsTimes.taskID
GROUP BY p.projectName, p.projectID, t.lastUpdate, billingsTimes.userID
答案 0 :(得分:0)
我认为您不需要在项目表中添加新列。看起来您已经在2个表之间建立了关系。如果您正在查看给定项目的上次更新时间,请尝试以下操作:
SELECT p.projectID, p.projectName, MAX(t.lastUpdate) as 'Last Updated Time'
FROM Tasks AS t INNER JOIN
Projects_tasks ON t.taskID = Projects_tasks.taskID INNER JOIN
Projects AS p ON Projects_tasks.projectID = p.projectID
GROUP BY p.projectName, p.projectID
- 编辑
要显示UserId
,请尝试以下操作:
SELECT p.projectID, p.projectName, BillingsTimes.UserId, MAX(t.lastUpdate) as 'Last Updated Time'
FROM Tasks AS t INNER JOIN
Projects_tasks ON t.taskID = Projects_tasks.taskID INNER JOIN
Projects AS p ON Projects_tasks.projectID = p.projectID INNER JOIN
BillingsTimes ON t.taskID = BillingsTimes.taskID
GROUP BY p.projectName, p.projectID, BillingsTimes.UserId