improved db:aggregate()

The improvement enables the user to aggregate only distinct values.