Erics svar kan være en smule forbedret:
select
sp1.sid as sid1,
sp2.sid as sid2,
count(*) as num
from
sp as sp1
inner join sp as sp2 on sp1.pid=sp2.pid and sp1.sid<sp2.sid
group by sp1.sid, sp2.sid
;
Brug for at undgå at få (1,4,2) OG (4,1,2)