Implement SELECT aggregates

This implements SELECT aggregates, as discussed in #1. Depends on #10 and #11.