本文介绍了选择第二个最大访问表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码用于返回表中所有日期中倒数第二个日期的所有项目名称.但是,我不断收到错误消息您的查询未将指定的表达式'Project Name'作为聚合函数的一部分.我在做什么不正确?

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 MaxReportDateFROM RedProjectHistoricalWHERE (((RedProjectHistorical.[Report Date]) Not In (Select Max([Report Date]) FROM RedProjectHistorical)));

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

推荐答案

尝试更简单的方法:

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;

这篇关于选择第二个最大访问表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:03
查看更多