From the docs:
You can't use a LIMIT clause in a query that uses an aggregate
function, but does not use a GROUP BY clause.
Some object fields have a field type that does not support grouping.
You can't include fields with these field types in a GROUP BY clause.
The Field object associated with DescribeSObjectResult has a groupable
field that defines whether you can include the field in a GROUP BY
There are basically 2 ways for you.
You can do a simple SOQL order by Lastmodifieddate with a limit 100 and it will return you a list of records.
So the first record's lastmodifieddate will be
min(lastmodifieddate) and that of the last one will be
max(lastmodifieddate). List size will be the count.
You can do this using 2 SOQL queries.
First fetch the first 100 records using a simple SOQL with a limit 100.
SELECT Id FROM Account LIMIT 100
save the result in a list, lets say -
Now, do your Aggregate query filtering the records using the list.
SELECT MAX(LastModifiedDate),MIN(LastModifiedDate), count(Id) FROM Account where Id IN :accList
There is a date function in SOQL - DAY_ONLY
This function returns the DAY part of the Datetime value. This function if used in a SOQL, the field can be grouped as well.
SELECT DAY_ONLY(LastModifiedDate), count(Id) FROM Account group by DAY_ONLY(LastModifiedDate) order by DAY_ONLY(LastModifiedDate) LIMIT 10
Notice here: The LIMIT 10 is not applied to the actual account list but on the aggregated rows.
So if you want to aggregate on the first 100 records, there is simply no way using single Aggregate Query.