0

我正在尝试在 MS Access 2010 数据库中运行以下查询:

SELECT a.[Level], max(a.dte) AS nextDate, IIf(a.[Type1Date]<a.[Type2Date],"t1","t2") AS Type
FROM (
    select [Level], Type1Date as dte, Type1Date, Type2Date 
    FROM CommunicationTable WHERE ClientNumber=1
    UNION
    select [Level], Type2Date as dte, Type1Date, Type2Date 
    FROM CommunicationTable WHERE ClientNumber = 1
)  AS a
GROUP BY a.[Level];  

但是,Access 给了我一个对话框,说明:

You tried to execute a query that does not include the specified  
expression 'IIf(a.[Type1Date]<a.[Type2Date],"t1","t2")' as part  
of an aggregate function.  

谁能解释这意味着什么并告诉我如何修复代码,以便它返回我请求的字段(级别、下一个日期、类型)?

4

1 回答 1

4

对于组查询,您不能在 Select 语句中包含列,除非它们也在 Group By 语句或聚合中。所以你可能想使用:

GROUP BY a.[Level], IIf(a.[Type1Date]<a.[Type2Date],"t1","t2")
于 2013-10-04T19:42:03.377 回答