0

我遇到了这个问题我正在尝试获取与项目相关的最后一个任务更新任务以及如何通过获取最后一个 billingTime 来进行更新
我也有 Copley of design Questions

  • 获取项目和上次更新时间表单任务的最佳方式是什么?我应该使用createdOn列 Form billingTime
  • 我应该在项目表上添加新列来记录最后更新的任务吗?

在此处输入图像描述

我的查询:

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
4

1 回答 1

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
于 2013-01-11T19:52:54.880 回答