选择第二个最大访问表

时间:2016-05-03 19:06:27

标签: ms-access-2013 access

以下代码用于返回表中所有日期的第二个最近日期的所有项目名称。然而,我继续收到错误“您的查询不包含指定的表达式'项目名称'作为聚合函数的一部分。我做错了什么?

SELECT DISTINCT TOP 2 Max([Report Date]) AS MaxReportDate FROM RedProjectHistorical WHERE (((RedProjectHistorical.[Report Date]) Not In (Select Max([Report Date]) FROM RedProjectHistorical)));

1 个答案:

答案 0 :(得分:1)

尝试更简单:

SELECT DISTINCT TOP 2 
    [Report Date] AS MaxReportDate
FROM 
    RedProjectHistorical
WHERE 
    [Report Date] Not In 
        (SELECT Max(T.[Report Date]) FROM RedProjectHistorical As T)
ORDER BY
    [Report Date] Desc;