Select second max Access table

2019-09-07 03:05发布

The following code is meant to return all project names for the second most recent date of all dates in the table. I however keep getting the error "Your query does not include the specified expression 'Project Name' as part of an aggregate function. What am I doing incorrectly?

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

1条回答
狗以群分
2楼-- · 2019-09-07 03:51

Try with the simpler:

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;
查看更多
登录 后发表回答