2013-10-04 133 views
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. 

灿任何人都可以解释这是什么意思,并告诉我如何修复代码,以便它返回我请求的字段(Level,nextDate,Type)?

回答

4

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

GROUP BY a.[Level], IIf(a.[Type1Date]<a.[Type2Date],"t1","t2")