我正在使用MS access 2007,这是我原来的SQL查询:
SELECT Rates.UNIT, Rates.PROJECT, Rates.[Date_of_CM Memo], Rates.Rates, Rates.REMARKS
FROM Rates, Checks
WHERE (((Rates.UNIT)=[Checks].[Unit_Name]) AND ((Rates.[Date_of_CM Memo])<[Checks].[Reg_Date]));
但是当我修改此查询(下面)以显示最新日期的记录时,我收到一条错误消息,说我不能将max函数与where子句一起使用:
SELECT Rates.UNIT, Rates.PROJECT, Rates.[Date_of_CM Memo], Rates.Rates, Rates.REMARKS
FROM Rates, Checks
WHERE (((Rates.UNIT)=[Checks].[Unit_Name]) AND (MAX((Rates.[Date_of_CM Memo])<[Checks].[Reg_Date])));
答案 0 :(得分:2)
您不能只将MAX
(或任何其他汇总功能)放入 WHERE ,
但你可以像这样放一个查询:
SELECT Rates.Unit,
Rates.Project,
Rates.[Date_of_CM Memo],
Rates.Rates,
Rates.Remarks
FROM Rates,
Checks
WHERE (((Rates.Unit) = [Checks].[Unit_Name]) AND
((SELECT MAX (Rates.[Date_of_CM Memo])
FROM Rates) < [Checks].[Reg_Date])));