Credo che questa query farà quello che vuoi:
SELECT array_agg(players), player_teams
FROM (
SELECT DISTINCT t1.t1player AS players, t1.player_teams
FROM (
SELECT
p.playerid AS t1id,
concat(p.playerid,':', p.playername, ' ') AS t1player,
array_agg(pl.teamid ORDER BY pl.teamid) AS player_teams
FROM player p
LEFT JOIN plays pl ON p.playerid = pl.playerid
GROUP BY p.playerid, p.playername
) t1
INNER JOIN (
SELECT
p.playerid AS t2id,
array_agg(pl.teamid ORDER BY pl.teamid) AS player_teams
FROM player p
LEFT JOIN plays pl ON p.playerid = pl.playerid
GROUP BY p.playerid, p.playername
) t2 ON t1.player_teams=t2.player_teams AND t1.t1id <> t2.t2id
) innerQuery
GROUP BY player_teams
Result:
PLAYERS PLAYER_TEAMS
2:Allen,3:Pierce 1,3
4:Garnett,5:Perkins
Usa array_agg sul teamid per ogni giocatore in plays
per abbinare giocatori con la stessa configurazione di squadra. Ad esempio, ho incluso una colonna con le squadre, ma che può essere rimossa senza influire sui risultati purché non venga rimossa dalla clausola gruppo per.
Esempio SQL Fiddle. Testato con Postgesql 9.2.4
EDIT:corretto un errore che duplicava le righe.