【发布时间】:2012-11-13 13:35:09
【问题描述】:
我正在寻找以下输出
- 10 位客户在 2 个产品组中购买了 10 件商品
- 8 位客户在 1 个产品组中购买了 10 件商品。
通常是一个矩阵,其中客户数量超过购买的商品和产品组,即。计算超过 2 个属性(项目和产品组)
我尝试了下面的代码,但它只给了我
- 1 位客户拥有 10 个项目和 2 个产品组
- 1 位客户拥有 10 件商品和 1 个产品组,尽管每行的客户更多:
sn-p,
count (distinct customer_id) over (Partition by customer_id) as Customer_ID
,count (distinct customer_shipment_item_id) Over (Partition by customer_id) as customer_items
,count (distinct product_group) Over (Partition by customer_id) as customer_product_groups
您能解释一下这是如何工作的吗?
【问题讨论】:
-
如果您提供架构和数据示例会更容易,SQL Fiddle 可能是
-
嗨 Roman,我可以在这里添加一张桌子吗?每次我尝试添加一些 excel 示例时,格式都会中断。谢谢比安卡