sql >> Base de Datos >  >> RDS >> PostgreSQL

Consulta SQL 6 grados de separación para análisis de red

Creo que esto es lo que quisiste decir:

with recursive tc as(
select $1 as player_id, 1 as level
  union
select ph2.player_id, level+1
  from tc, phone_hashes ph1, phone_hashes ph2
  where tc.player_id=ph1.player_id
  and ph1.hash=ph2.hash
  and tc.level < 6  
)    
select distinct player_id from tc