I have the following query:
SELECT tblDifferentDates.FixDate, tblDifferentDates.BookCode, tblDifferentDates.HAH, Sum(tblDifferentDates.Quantity) AS SumOfQuantity
FROM tblDifferentDates
GROUP BY tblDifferentDates.FixDate, tblDifferentDates.BookCode, tblDifferentDates.HAH
HAVING (((tblDifferentDates.FixDate) Is Not Null))
ORDER BY tblDifferentDates.HAH, Sum(tblDifferentDates.Quantity) DESC;
which returns a set of records of the following nature:
FixDate BookCode HAH SumOfQuantity
27-Feb-07 1111 Test1 14370
27-Feb-07 2222 Test1 3816
27-Feb-07 3333 Test1 0
27-Feb-07 Ex1 Test1 0
27-Feb-07 Ex2 Test1 -27
27-Feb-07 4444 Test1 -2036
My question is how would I mod the SQL to only return the record that has the highest SumOfQuantity?
Bear in mind that the query also returns a heap of records where the HAH field is Test2 and I would like to return the record with the highest SumOfQuantity amount for these set of records also.
My point is, I think that this rules out the "TOP" option doesn't it?
Pls help!
SELECT tblDifferentDates.FixDate, tblDifferentDates.BookCode, tblDifferentDates.HAH, Sum(tblDifferentDates.Quantity) AS SumOfQuantity
FROM tblDifferentDates
GROUP BY tblDifferentDates.FixDate, tblDifferentDates.BookCode, tblDifferentDates.HAH
HAVING (((tblDifferentDates.FixDate) Is Not Null))
ORDER BY tblDifferentDates.HAH, Sum(tblDifferentDates.Quantity) DESC;
which returns a set of records of the following nature:
FixDate BookCode HAH SumOfQuantity
27-Feb-07 1111 Test1 14370
27-Feb-07 2222 Test1 3816
27-Feb-07 3333 Test1 0
27-Feb-07 Ex1 Test1 0
27-Feb-07 Ex2 Test1 -27
27-Feb-07 4444 Test1 -2036
My question is how would I mod the SQL to only return the record that has the highest SumOfQuantity?
Bear in mind that the query also returns a heap of records where the HAH field is Test2 and I would like to return the record with the highest SumOfQuantity amount for these set of records also.
My point is, I think that this rules out the "TOP" option doesn't it?
Pls help!