Basic framework for doing simple SQL aggregation queries