Grouping results

Hi all,
having a dataset like

a

…n times…

a


b

…m times…

b

I would like to get the result of counting documents grouped by .
Ok, with just two item1 possibilities it makes sense to send two diferent queries but how should be done with a non defined number of item1 posibilities?

Any idea?
thanks.
Gorka

I am still looking for a smart way to simulate a tipical SQL sortby query. Is X-tension the right direction to take?
Anyone out there having similar needs???
Thanks for your responses.