在Access中返回最大值

时间:2017-04-18 13:03:23

标签: ms-access

我使用下面的代码返回最大值

SELECT t2.QUOTEID, t2.SALES_REF, Max(t1.OBJECTION_LEVEL) AS MaxOfOBJECTION_LEVEL, t1.OBJECTION_CALL_DATE
FROM TBLOBJECTIONSNEW AS t1 RIGHT JOIN TBLQUOTESNEW AS t2 ON t1.QUOTE_ID = t2.QUOTEID
GROUP BY t2.QUOTEID, t2.SALES_REF, t1.OBJECTION_CALL_DATE
HAVING (((Max(t1.OBJECTION_LEVEL)) Is Not Null));

但是,当我运行此代码时,会返回3条记录,因为有3种不同的OBJECTION_CALL_DATE&#39>

如何只返回一条记录 - 最大值为t1.OBJECTION_LEVEL?

1 个答案:

答案 0 :(得分:0)

能够自己解决这个问题: -

SELECT t2.QUOTEID, t2.SALES_REF, t1.OBJECTION_LEVEL, t1.OBJECTION_CALL_DATE
FROM TBLOBJECTIONSNEW as t1 RIGHT JOIN TBLQUOTESNEW as t2 ON t1.QUOTE_ID = t2.QUOTEID
WHERE (((t1.[OBJECTION_LEVEL])=(SELECT MAX(OBJECTION_LEVEL) FROM TBLOBJECTIONSNEW t3 where t1.QUOTE_ID = t3.QUOTE_ID)))