0

我想生成一个项目进度报告,其中几乎包括检查给定时间范围内已完成里程碑的百分比。(例如:A 公司今天有 10 个到期里程碑,但只有 8 个标记为已完成,因此它们的进度比计划慢 20%。)

这部分很简单,而且效果很好,但是在生成它之前,我确定项目计划是否获得批准。已批准的项目计划是具有里程碑 1 和 2 = 100 的项目计划。

您可以在下面看到我必须使用的表结构。

ID          Company     Project     Milestone   Date        Completion
170825240   Company A   Project 1   Milestone 1 29.10.12    100
170825311   Company A   Project 1   Milestone 2 29.10.12    0
170825242   Company A   Project 1   Milestone 3 05.11.12    100
170825173   Company A   Project 1   Milestone 4 17.12.12    0
170825104   Company B   Project 1   Milestone 1 29.10.12    100
170825035   Company B   Project 1   Milestone 2 29.10.12    100
170824966   Company B   Project 1   Milestone 3 05.11.12    100
170824897   Company B   Project 1   Milestone 4 17.12.12    0
170824828   Company C   Project 1   Milestone 1 29.10.12    100
170824759   Company C   Project 1   Milestone 2 29.10.12    100
170824690   Company C   Project 1   Milestone 3 05.11.12    0
170824621   Company C   Project 1   Milestone 4 17.12.12    0

在此快照中,项目 1 被批准用于公司 B 和 C。

我面临的问题是如何在单个查询进度中组合仅过滤已批准的计划。我不想手动编写异常,因为我们正在讨论公司和项目的 1600 种组合。

有人知道怎么做吗?

谢谢!!!!

更新

SELECT S1.[Company], COUNT(S1.[Milestone]) AS ShouldBeMilestones

FROM Sheet1 AS S1

INNER JOIN Sheet1 S2
ON S2.[Company] = S1.[Company]
AND S2.[Project] = S1.[Project]
AND S2.[Milestone] = 'Milestone 1'
AND S2.[%compl#] = 100

INNER JOIN Sheet1 S3
ON S3.[Company] = S1.[Company]
AND S3.[Project] = S1.[Project]
AND S3.[Milestone] = 'Milestone 2'
AND S3.[%compl#] = 100

WHERE ((S1.[Task class] <> 'A') AND (S1.[Task class] <> 'B') AND (S1.[Task class] <> ''))
AND S1.[Milestone] NOT LIKE '0.*' AND S1.[Milestone] NOT LIKE '1.*'
AND S1.[Start] <= Now()

GROUP BY S1.[Company];
4

2 回答 2

1

添加两个where条件,每个条件都检查里程碑的完成情况:

from    Milestones m
where   exists
        (
        select  *
        from    Milestones m1
        where   m1.Company = m.Company
                and m1.Project = m.Project
                and m1.Milestone = 'Milestone 1'
                and m1.Completion = 100
        )
        and exists
        (
        select  *
        from    Milestones m2
        where   m2.Company = m.Company
                and m2.Project = m.Project
                and m2.Milestone = 'Milestone 2'
                and m2.Completion = 100
        )
于 2012-12-17T12:58:44.127 回答
1

这也可以通过从上一个答案中借用的连接来实现;)

select m.* 
(from    Milestones m
inner join Milesones as m1 
      on m1.Company = m.Company
      and m1.Project = m.Project
      and m1.Milestone = 'Milestone 1'
      and m1.Completion = 100)
inner join Milestones as m2
        on m2.Company = m.Company
                and m2.Project = m.Project
                and m2.Milestone = 'Milestone 2'
                and m2.Completion = 100

编辑应该解决一些 ms 访问问题,但不能老实说访问测试它我没有看到 () 围绕第一次加入的好处

于 2012-12-17T13:04:14.250 回答