Building off of the question "SQL - Turn relationship IDs into a delimited list", I'd like to further group the results by unique sets of sites. For example, using the same data in that question:
Sites 15 & 16 together share one permutation of a,b,c. Sites 18, 19, 20 share another permutation. Site 17 uses BOTH permutations.
I'd like to find a query with results similar to the linked question, but without any overlap in the site_ids:
I'm not sure that it's possible with just SQL, and I may just have to build something to crunch the data in code, but I'm crossing my fingers...
I'm using SQL Server, but it would also be nice to know how to do it with postgres.
UPDATE:
Someone suggested that Simulating group_concat MySQL function in Microsoft SQL Server 2005? might be a duplicate. From my (limited) understanding of group_concat, it appears that it might duplicate the question referenced above, but not this question. This question needs no overlap in site_ids.