Select second max Access table

不问归期 提交于 2019-12-12 02:28:43

问题


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:


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;


来源:https://stackoverflow.com/questions/37012421/select-second-max-access-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!