0

我有下表,我们在其中存储项目计划:

ID    PROJECT_NAME   MILESTONE_NAME

所有里程碑都以数字开头,例如“0.1 - 里程碑描述”。

我想检索按项目订购的 MAX MILESTONE_NAME。

我使用了以下代码,但它不起作用......

SELECT Sheet1.[PROJECT_NAME], MAX(Sheet1.[MILESTONE_NAME])
FROM Sheet1 INNER JOIN Sheet1 AS Sheet1_1 ON (Sheet1.[PROJECT_NAME] = Sheet1_1.[PROJECT_NAME]) AND (Sheet1.[MILESTONE_NAME] = Sheet1_1.[MILESTONE_NAME])
ORDER BY Sheet1.[PROJECT_NAME]

它说 PROJECT_NAME 不在聚合函数中。

你们知道我应该如何前进吗?

谢谢!

4

2 回答 2

1

你必须GROUP BY Sheet1.[PROJECT_NAME]

尝试 :

SELECT Sheet1.[PROJECT_NAME], MAX(Sheet1.[MILESTONE_NAME])
FROM Sheet1
    INNER JOIN Sheet1 AS Sheet1_1 ON (Sheet1.[PROJECT_NAME] = Sheet1_1.[PROJECT_NAME])
        AND (Sheet1.[MILESTONE_NAME] = Sheet1_1.[MILESTONE_NAME])
GROUP BY Sheet1.[PROJECT_NAME]
ORDER BY Sheet1.[PROJECT_NAME]
于 2013-01-17T13:12:52.587 回答
0

添加到查询:

GROUP BY Sheet1.[PROJECT_NAME];
于 2013-01-17T13:13:08.017 回答