我有下表,其中存储了项目计划:
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不在聚合功能中。
你们有什么想法我应该如何前进?
谢谢!
答案 0 :(得分: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]
答案 1 :(得分:0)
添加到查询中:
GROUP BY Sheet1.[PROJECT_NAME];