2

How do I aggregate like sets of data.
The example below shows how the raw data and desired output.
DECLARE @Data TABLE (PID INT, CID INT)
INSERT INTO @Data
VALUES (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), (3, 3), (2, 1), (2, 2), (4, 3), (4, 4),
(5, 4), (5, 5), (8, 4), (8, 5), (6, 6), ...