Jeg tror, at denne forespørgsel vil gøre, hvad du vil:
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
Den bruger array_agg over teamet for hver spiller i plays
at matche spillere med nøjagtig samme holdkonfiguration. Jeg inkluderede f.eks. en kolonne med holdene, men den kan fjernes uden at påvirke resultaterne, så længe den ikke er fjernet fra gruppen efter klausul.
SQL Fiddle-eksempel. Testet med Postgesql 9.2.4
EDIT:Rettede en fejl, der duplikerede rækker.