计算同一客户购买的产品对

Count product-pairs that have been purchased by same customer

我有 table 个客户购买的每个产品的客户产品条目

cust, prod
A,1
A,3
B,1
B,2
B,3

我想最终创建一个产品矩阵,其中包含购买产品对的客户数量

   1, 2, 3
1, -, 1, 2
2, 1, -, 1
3, 2, 1, -

所以,我的问题是如何将第一个 table 转换成类似

的东西
prod1, prod2, count
1, 2, 1
1, 3, 2
2, 1, 1
2, 3, 1
3, 1, 2
3, 2, 1

你在这里回答了这个问题:

How to find what products sell well with others in an SQL Server Query

您将使用 客户

,而不是 sale_id