我对如何优化配置单元代码有问题。我有一张巨大的table如下:
Customer_id Product_id Date Value
1 1 02/28 100.0
1 2 02/02 120.0
1 3 02/10 144.0
2 2 02/15 120.0
2 3 02/28 144.0
... ... ... ...
我想创建一个复杂的网络,通过买家将产品联系起来。图形不必定向,我必须计算它们之间的链接数。最后我需要这个:
Product_x Product_y amount
1 2 1
1 3 1
2 3 2
有人能帮我吗?我需要一个优化的方法来做到这一点。表与自身的连接不是解决方案。我真的需要一个最佳的方法=/
CREATE TABLE X AS
SELECT
a.product_id as product_x,
b.product_id as product_y,
count(*) as amout
FROM table as a
JOIN table as b
ON a.customer_id = b.customer_id
WHERE a.product_id < b.product_id
GROUP BY product_x, product_y;
暂无答案!
目前还没有任何答案,快来回答吧!