How to aggregate only parts of members of each group in one query statement in PG? I have a table people(gid int, name varchar) with data: