Using aggregation with output in cursor mode