Agrupe uma auto-junção:
SELECT a.uid a, b.uid b, COUNT(*) cnt
FROM my_table a JOIN my_table b ON b.id = a.id AND b.uid > a.uid
GROUP BY a.uid, b.uid
Veja em sqlfiddle .
SELECT a.uid a, b.uid b, COUNT(*) cnt
FROM my_table a JOIN my_table b ON b.id = a.id AND b.uid > a.uid
GROUP BY a.uid, b.uid